Skip to content

Enabling and disabling the PHP output_buffering directive

The output_buffering directive in PHP controls how output is sent to the client. By default, PHP sends output in multiple chunks as the script runs. When output_buffering is enabled, PHP stores the output in memory and sends it only after the script finishes processing.

  • Send headers after output begins: Useful when you need to modify headers even after content has started.
  • Improve performance: Reduces the number of packets sent to the client, which can speed up page loads.
  • Control output flow: Allows developers to flush output at specific times.

Edit or create a custom php.ini file in your application directory:

output_buffering = On

You can also specify a buffer size:

output_buffering = 16384

This sets the maximum buffer size to 16 KB.

If your hosting environment supports .user.ini, add:

output_buffering = On

On Apache servers, you can override the directive:

php_value output_buffering On
output_buffering = Off
output_buffering = Off
php_value output_buffering Off