PHP Output Buffering Control
The output buffering controls the output data from the PHP scripts.
Example to controls the output of a script
<?php
ob_start();
echo "Hello\n";
setcookie("cookiename", "cookiedata");
ob_end_flush();
?>
Requirements
No external libraries are needed to build this extension.
Installation
There is no installation needed to use these functions;
They are part of the PHP core.
Run-time Configuration
The behavior of these functions is affected by settings in php.ini.
Output Control configuration options
Name | Default | Changeable | Changelog |
---|---|---|---|
output_buffering | "0" | PHP_INI_PERDIR | |
output_handler | NULL | PHP_INI_PERDIR | Available since PHP 4.0.4. |
implicit_flush | "0" | PHP_INI_ALL | PHP_INI_PERDIR in PHP <= 4.2.3. |
url_rewriter.tags | "a=href,area=href,frame=src,form=,fieldset=" | PHP_INI_ALL |
Available since PHP 4.0.4. Before PHP 7.1.0, This was used to set the session's trans sid rewrite. From PHP 7.1.0, it is only used by output_add_rewrite_var(). |
url_rewriter.hosts | $_SERVER['HTTP_HOST'] is used as default. | PHP_INI_ALL | Available since PHP 7.1.0 |
Resource Types
This extension has no resource types defined.
Predefined Constants
The constants below are always available as part of the PHP core.
- PHP_OUTPUT_HANDLER_START (integer)
- This indicates that output buffering has begun.
- PHP_OUTPUT_HANDLER_WRITE (integer)
- Indicates that the output buffer is being flushed, and had data to output.
- Available since PHP 5.4.
- PHP_OUTPUT_HANDLER_FLUSH (integer)
- This indicates that the buffer has been flushed.
- Available since PHP 5.4.
- PHP_OUTPUT_HANDLER_CLEAN (integer)
- This indicates that the output buffer has been cleaned.
- Available since PHP 5.4.
- PHP_OUTPUT_HANDLER_FINAL (integer)
- This indicates that this is the final output buffering operation.
- Available since PHP 5.4.
- PHP_OUTPUT_HANDLER_CONT (integer)
- This indicates that the buffer has been flushed, but output buffering will continue.
- As of PHP 5.4, this is an alias for PHP_OUTPUT_HANDLER_WRITE.
- PHP_OUTPUT_HANDLER_END (integer)
- This indicates that output buffering has ended.
- As of PHP 5.4, this is an alias for PHP_OUTPUT_HANDLER_FINAL.
- PHP_OUTPUT_HANDLER_CLEANABLE (integer)
- Controls whether an output buffer created by ob_start() can be cleaned.
- Available since PHP 5.4.
- PHP_OUTPUT_HANDLER_FLUSHABLE (integer)
- Controls whether an output buffer created by ob_start() can be flushed.
- Available since PHP 5.4.
- PHP_OUTPUT_HANDLER_REMOVABLE (integer)
- Controls whether an output buffer created by ob_start() can be removed before the end of the script.
- Available since PHP 5.4.
- PHP_OUTPUT_HANDLER_STDFLAGS (integer)
- The default set of output buffer flags;
- currently equivalent to PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_FLUSHABLE | PHP_OUTPUT_HANDLER_REMOVABLE.
- Available since PHP 5.4.
Output Buffering Control Functions
-
flush — Flush system output buffer
-
ob_clean — Clean (erase) the output buffer
-
ob_end_clean — Clean (erase) the output buffer and turn off output buffering
-
ob_end_flush — Flush (send) the output buffer and turn off output buffering
-
ob_flush — Flush (send) the output buffer
-
ob_get_clean — Get current buffer contents and delete current output buffer
-
ob_get_contents — Return the contents of the output buffer
-
ob_get_flush — Flush the output buffer, return it as a string and turn off output buffering
-
ob_get_length — Return the length of the output buffer
-
ob_get_level — Return the nesting level of the output buffering mechanism
-
ob_get_status — Get status of output buffers
-
ob_gzhandler — ob_start callback function to gzip output buffer
-
ob_implicit_flush — Turn implicit flush on/off
-
ob_list_handlers — List all output handlers in use
-
ob_start — Turn on output buffering
-
output_add_rewrite_var — Add URL rewriter values
-
output_reset_rewrite_vars — Reset URL rewriter values