What Output Is Buffered?

PHP's user-level output buffers buffer all output after they are started until they are turned off or the script ends. Output in the context of PHP's user-level output buffer is everything that PHP would display or send back to the browser. In practical terms, output is non-zero length data that is:

  • outside of the <?php ?> tags
  • printed by language constructs and functions whose explicit purpose is to output user provided variables or strings such as echo, print, printf, var_dump, var_export, vprintf
  • printed by functions whose purpose is to collect and output data/information on the running script or PHP such as debug_print_backtrace, phpcredits, phpinfo, ReflectionExtension::info
  • printed by PHP on an uncaught exception or an unhandled error (subject to the settings of display_errors and error_reporting)
  • anything written to php://output

注意: Data that is written directly to stdout or passed to an SAPI function with a similar functionality will not be captured by user-level output buffers. This includes writing data to stdout with fwrite or sending headers using header or setcookie.