File: output-buffering.xml

package info (click to toggle)
php-doc 20241205~git.dfcbb86%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 70,956 kB
  • sloc: xml: 968,269; php: 23,883; javascript: 671; sh: 177; makefile: 37
file content (113 lines) | stat: -rw-r--r-- 3,866 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?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
-->