Skip to content

Setting the output_buffering directive in an .htaccess file

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

  • Enable buffering: Allows headers to be sent after output begins and may improve performance.
  • Disable buffering: Useful for streaming data or applications that require immediate output.

Steps to Configure output_buffering in .htaccess

Section titled “Steps to Configure output_buffering in .htaccess”
  • Log in to cPanel or use FTP/File Manager.
  • Navigate to your site’s root directory (e.g., /public_html).
  1. If .htaccess already exists, open it for editing.
  2. If not, create a new file named .htaccess.

Insert one of the following lines depending on your needs:

# Enable output buffering
php_value output_buffering On
# Disable output buffering
php_value output_buffering Off
# Enable with a specific buffer size (e.g., 16 KB)
php_value output_buffering 16384
  1. Save the .htaccess file.

  2. Create a test file info.php with:

    <?php phpinfo(); ?>
  3. Load it in your browser and search for output_buffering.

  4. Confirm the new value is active.

  5. Delete the test file afterward for security.

  • Enable buffering for performance optimization and flexibility with headers.
  • Disable buffering for streaming applications or real‑time output.
  • Use moderate buffer sizes to balance memory usage and speed.