mirror of
https://github.com/macintoshplus/doc-en.git
synced 2026-03-24 08:52:18 +01:00
114 lines
3.8 KiB
XML
114 lines
3.8 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<chapter xml:id="outcontrol.output-buffering" xmlns="http://docbook.org/ns/docbook">
|
|
<title>Output Buffering</title>
|
|
<para>
|
|
Output buffering is the buffering (temporary storage) of output
|
|
before it is flushed (sent and discarded) to the browser (in a web context)
|
|
or to the shell (on the command line).
|
|
While output buffering is active no output is sent from the script,
|
|
instead the output is stored in an internal buffer.
|
|
</para>
|
|
|
|
<section>
|
|
<title>Buffering Affecting PHP</title>
|
|
<para>
|
|
PHP relies on the underlying software/hardware infrastructure
|
|
when flushing output.
|
|
Buffering implemented by consoles on the command line (e.g. line buffered)
|
|
or web servers and browser in a web context (e.g. fully buffered)
|
|
do affect when output is displayed to the end-user.
|
|
Some of these effects can be eliminated by fine-tuning server settings
|
|
and/or aligning buffer sizes of the various layers.
|
|
</para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Output Buffering Control In PHP</title>
|
|
<para>
|
|
PHP provides a fully buffered user-level output buffer
|
|
with functions to start, manipulate and turn off the buffer
|
|
(most <link linkend="ref.outcontrol">ob_<replaceable>*</replaceable></link> functions),
|
|
and two functions to flush the underlying system buffers
|
|
(<function>flush</function> and <function>ob_implicit_flush</function>).
|
|
Some of this functionality can be set and/or configured
|
|
using the appropriate &php.ini; settings as well.
|
|
</para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Use Cases</title>
|
|
<para>
|
|
Output buffering is generally useful in situations when the buffered output
|
|
is modified or inspected, or it is used more than once in a request;
|
|
or when the controlled flushing of output is desired.
|
|
Specific use cases include:
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara>
|
|
caching the result of compute/time intensive scripts
|
|
for example by generating static <literal>HTML</literal> pages
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
re-using the generated output by displaying it, saving it to a file
|
|
and/or sending it by email
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
flushing the <literal>head</literal> of an <literal>HTML</literal> page
|
|
separate from the <literal>body</literal> allows browsers
|
|
to load external resources while the script executes
|
|
potentially more time consuming processes
|
|
(e.g. database/file access, external network connection).
|
|
This is only useful if the <literal>HTTP</literal> status code
|
|
cannot change after the headers are sent
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
extracting information from functions that would otherwise produce output
|
|
(e.g. <function>phpinfo</function>)
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
controlling the output of third-party code by modifying/using parts
|
|
(e.g. extracting data, replacing words/phrases,
|
|
adding missing <literal>HTML</literal> tags),
|
|
or discarding it entirely under certain conditions (e.g. errors)
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
polyfilling certain unavailable web server functionality
|
|
(e.g. compressing or encoding output)
|
|
</simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
</para>
|
|
</section>
|
|
|
|
</chapter>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|