<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/book.outcontrol.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'outcontrol.flushing-system-buffers.php',
    1 => 'Flushing System Buffers',
    2 => 'Flushing System Buffers',
  ),
  'up' => 
  array (
    0 => 'book.outcontrol.php',
    1 => 'Output Control',
  ),
  'prev' => 
  array (
    0 => 'outcontrol.output-buffering.php',
    1 => 'Output Buffering',
  ),
  'next' => 
  array (
    0 => 'outcontrol.user-level-output-buffers.php',
    1 => 'User-Level Output Buffers',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/outcontrol/flushing-system-buffers.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="outcontrol.flushing-system-buffers" class="chapter">
 <h1 class="title">Flushing System Buffers</h1>

 <p class="para">
  PHP provides two related ways
  to flush (send and discard the contents of) system buffers:
  through calling <span class="function"><a href="function.flush.php" class="function">flush()</a></span>
  and through enabling implicit flushing
  with <span class="function"><a href="function.ob-implicit-flush.php" class="function">ob_implicit_flush()</a></span>
  or the <a href="outcontrol.configuration.php#ini.implicit-flush" class="link">implicit_flush</a>
  <var class="filename">php.ini</var> setting.
 </p>

 <div class="section">
  <h2 class="title">Output Flushing Behaviour</h2>
  <p class="para">
   With implicit flushing disabled, PHP will flush output only
   when <span class="function"><a href="function.flush.php" class="function">flush()</a></span> is called or when the script ends.
  </p>
  <p class="para">
   With implicit flushing enabled, PHP will attempt to flush
   after every block of code resulting in output.
   Output in this context is non-zero length data that is:
   <ul class="itemizedlist">
    <li class="listitem">
     <span class="simpara">
      outside of the <code class="literal">&lt;?php ?&gt;</code> tags
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      printed by language constructs and functions
      whose explicit purpose is to output user provided variables or strings such as
      <span class="function"><a href="function.echo.php" class="function">echo</a></span>, <span class="function"><a href="function.print.php" class="function">print</a></span>,
      <span class="function"><a href="function.printf.php" class="function">printf()</a></span>, <span class="function"><a href="function.var-dump.php" class="function">var_dump()</a></span>,
      <span class="function"><a href="function.var-export.php" class="function">var_export()</a></span>, <span class="function"><a href="function.vprintf.php" class="function">vprintf()</a></span>
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      printed by functions whose purpose is to collect and output
      data/information on the running script or PHP such as
      <span class="function"><a href="function.debug-print-backtrace.php" class="function">debug_print_backtrace()</a></span>, <span class="function"><a href="function.phpcredits.php" class="function">phpcredits()</a></span>,
      <span class="function"><a href="function.phpinfo.php" class="function">phpinfo()</a></span>,
      <span class="methodname"><a href="reflectionextension.info.php" class="methodname">ReflectionExtension::info()</a></span>
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      printed by PHP on an uncaught exception or an unhandled error
      (subject to the settings of
      <a href="errorfunc.configuration.php#ini.display-errors" class="link">display_errors</a>
      and <a href="errorfunc.configuration.php#ini.error-reporting" class="link">error_reporting</a>)
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      anything written to <code class="literal">php://output</code>
     </span>
    </li>
   </ul>
  </p>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <span class="simpara">
    Printing empty strings or sending headers is not considered output
    and will not result in a flush operation.
   </span>
  </p></blockquote>
  <div class="warning"><strong class="warning">Avviso</strong>
   <p class="simpara">
    If implicit flushing is enabled, control characters
    (e.g. <code class="literal">&quot;\n&quot;</code>, <code class="literal">&quot;\r&quot;</code>,
    <code class="literal">&quot;\0&quot;</code>)
    will trigger flushing as well.
   </p>
  </div>
 </div>

 <div class="section">
  <h2 class="title">Limitations</h2>
  <p class="para">
   This functionality cannot flush user-level output buffers.
   To use these together, user-level output buffers must be flushed
   before flushing system buffers in order for PHP to produce any output.
  </p>
  <div class="warning"><strong class="warning">Avviso</strong>
   <p class="simpara">
    Calling <span class="function"><a href="function.flush.php" class="function">flush()</a></span> or implicit flushing being enabled
    can interfere with output handlers of user-level output buffers
    that set and send headers in a web context
    (e.g. <span class="function"><a href="function.ob-gzhandler.php" class="function">ob_gzhandler()</a></span>)
    by sending headers before these handlers can do so.
   </p>
  </div>
  <p class="para">
   Buffering implemented by the underlying software/hardware
   cannot be overridden by PHP and should be taken into account
   when working with PHP&#039;s buffer control functions.
   Checking the web servers/browsers/consoles buffering settings
   and working with these can alleviate possible issues.
   Working in a web context, either the web server&#039;s buffering settings
   or the script&#039;s buffering could be adjusted to work in tandem
   whereas working around the buffering strategies of various browsers
   can be achieved by adjusting buffering in the PHP script.
   On consoles that implement line buffering,
   newline characters could be inserted in the appropriate places
   before flushing output.
  </p>
 </div>

 <div class="section">
  <h2 class="title"><abbr title="Server Application Programming Interface">SAPI</abbr> Differences In Flushing</h2>
  <p class="para">
   Although flushing is implemented by each <abbr title="Server Application Programming Interface">SAPI</abbr>
   in a slightly different way,
   these implementations fall in one of two categories:
   <ul class="itemizedlist">
    <li class="listitem">
     <span class="simpara">
      <abbr title="Server Application Programming Interface">SAPI</abbr>s used in a web context will flush headers first
      followed by the output.
      <code class="literal">Apache2Handler</code>, <code class="literal">CGI</code>,
      <code class="literal">FastCGI</code> and <code class="literal">FPM</code>
      are such <abbr title="Server Application Programming Interface">SAPI</abbr>s
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      other <abbr title="Server Application Programming Interface">SAPI</abbr>s
      such as <code class="literal">CLI</code> and <code class="literal">embed</code>
      will flush output only
     </span>
    </li>
   </ul>
  </p>
 </div>

</div>
<?php manual_footer($setup); ?>