PHP Function Reference

PHP - Output Control

The Output Control functions allow you to control when output is sent from the script. This can be useful in several different situations, especially if you need to send headers to the browser after your script has begun outputting data. The Output Control functions do not affect headers sent using header() or setcookie(), only functions such as echo and data between blocks of PHP code.


There is no installation needed to use these functions. These functions are part of the PHP core.

Runtime Configuration

The behavior of these functions is affected by settings in php.ini. See Runtime Configuration.

PHP Output 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() Returns 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() Returns the length of the output buffer.
ob_get_level() Returns 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() Turns implicit flush on/off.
ob_list_handlers() List all output handlers in use.
ob_start() Turns on output buffering.
output_add_rewrite_var() Add URL rewriter values.
output_reset_rewrite_vars() Reset URL rewriter values.

PHP Output Control Predefined Constants

The constants below are always available as part of the PHP core.

PHP_OUTPUT_HANDLER_STARTIntegerIndicates that output buffering has begun.
PHP_OUTPUT_HANDLER_WRITEIntegerIndicates that the output buffer is being flushed, and had data to output.
PHP_OUTPUT_HANDLER_FLUSHIntegerIndicates that the buffer has been flushed.
PHP_OUTPUT_HANDLER_CLEANIntegerIndicates that the output buffer has been cleaned.
PHP_OUTPUT_HANDLER_FINALIntegerIndicates that this is the final output buffering operation.
PHP_OUTPUT_HANDLER_CONTIntegerIndicates that the buffer has been flushed, but output buffering will continue. This is an alias for PHP_OUTPUT_HANDLER_WRITE.
PHP_OUTPUT_HANDLER_ENDIntegerIndicates that output buffering has ended. This is an alias for PHP_OUTPUT_HANDLER_FINAL.
PHP_OUTPUT_HANDLER_CLEANABLEIntegerControls whether an output buffer created by ob_start() can be cleaned.
PHP_OUTPUT_HANDLER_FLUSHABLEIntegerControls whether an output buffer created by ob_start() can be flushed.
PHP_OUTPUT_HANDLER_REMOVABLEIntegerControls whether an output buffer created by ob_start() can be removed before the end of the script.