Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

PHP Notice: ob_end_flush(): failed to send buffer of zlib output compression

ErrorNotice: ob_end_flush(): failed to send buffer of zlib output compression (1) in

Short answer

The notice comes from code that calls ob_end_flush() while zlib output compression is also handling the output. PHP lets compression act as the output handler, and it does not allow another handler beside it. Turn zlib.output_compression off, or keep it and clear output_handler, and stop flushing buffers you did not open.

  • Applies to PHP 8.3, PHP 8.4, WordPress 6.x, Apache, nginx
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the three settings that decide who handles output. This shows whether compression and a second handler are both active.

    php -r 'var_dump(ini_get("zlib.output_compression"), ini_get("output_handler"), ini_get("output_buffering"));'
  2. 2Match what you see, then jump to its fix

    1. 1zlib.output_compression prints 1 or On, and the notice appears at the end of the requestzlib.output_compression is On and the app also flushes buffers itselfFix
    2. 2ini_get('output_handler') returns something other than an empty stringoutput_handler is set while zlib.output_compression is OnFix
    3. 3The notice names ob_end_flush and points at a plugin or theme file, not at php.iniob_end_flush() is called on a buffer that cannot be removedFix

What does the error look like?

  • Notice: ob_end_flush(): failed to send buffer of zlib output compression (1) in

Cause 1 of 3

zlib.output_compression is On and the app also flushes buffers itself

1Check

With compression enabled, pages are compressed when the browser sends Accept-Encoding: gzip or deflate. The compression is the output handler, so code that closes buffers at shutdown can collide with it. The setting is off by default (0).

php --ini && php -i | grep -i "zlib.output_compression"

2Fix

Turn it off in php.ini and let the web server do the compression instead. The setting can also be changed in the Apache configuration or per request before any output is sent.

; php.ini
zlib.output_compression = Off

3Verify

Restart PHP-FPM or the web server, then load the page that raised the notice.

sudo systemctl restart php8.3-fpm

Confirmed by php.net

Did this fix it?

Cause 2 of 3

output_handler is set while zlib.output_compression is On

1Check

The manual states that output_handler must be empty when zlib.output_compression is On, and that no additional output handlers can be specified while compression is active.

php -i | grep -E "output_handler|zlib.output_compression"

2Fix

Empty output_handler. If you need a handler for the compressed output, use zlib.output_handler instead.

; php.ini
zlib.output_compression = On
output_handler =

3Verify

Reload the page and check that the notice is gone and the response is still compressed.

curl -s -D - -o /dev/null -H 'Accept-Encoding: gzip' https://example.com/

Confirmed by php.net

Did this fix it?

Cause 3 of 3

ob_end_flush() is called on a buffer that cannot be removed

1Check

ob_end_flush() needs an active buffer that was started with the PHP_OUTPUT_HANDLER_REMOVABLE flag. A failed call generates an E_NOTICE.

grep -R -n "ob_end_flush" wp-content/plugins wp-content/themes

2Fix

In your own code, only close buffers you opened with ob_start(). The manual's safer loop checks how many levels are open first.

while (ob_get_level() > 0) {
    ob_end_flush();
}

3Verify

Load the page and watch the PHP error log.

tail -n 20 /var/log/php8.3-fpm.log

Confirmed by php.net

Did this fix it?

How do I stop it coming back?

  • Compress in one place only: PHP or the web server, not both.
  • Keep output_handler empty unless you know which handler you want.
  • Update plugins and themes that start their own output buffers.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

CodeIgniter works locally but every page is 404 on the live server

The requested URL was not found on this server.

A 404 on the live server comes from one of four places: the document root is not the public folder, Apache ignores .htaccess or nginx has no try_files rule, the route is not defined because auto routing is off, or the controller file name differs from its class in case.

5 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.