PHP Notice: ob_end_flush(): failed to send buffer of zlib output compression
Notice: ob_end_flush(): failed to send buffer of zlib output compression (1) inShort 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.
Fix it fast
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"));'2Match what you see, then jump to its fix
- 1
zlib.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
ini_get('output_handler') returns something other than an empty stringoutput_handler is set while zlib.output_compression is OnFix - 3
The 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
- 1
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 = Off3Verify
Restart PHP-FPM or the web server, then load the page that raised the notice.
sudo systemctl restart php8.3-fpmConfirmed by php.net
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
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/themes2Fix
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.logConfirmed by php.net
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- Spotless LaundryAn on-demand laundry app: Flutter on a Laravel back end, with Firebase for live updates.
Related fixes
Back end
Chrome shows net::ERR_INCOMPLETE_CHUNKED_ENCODING on a PHP page
The page loads partly, then the response stops
The browser got a chunked response that ended before its final zero-length chunk, so the connection closed mid-page.
2 causes, each with a fixBack 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 fixBack end
Laravel file upload returns 413 behind nginx
413 Content Too Large
A 413 means a limit refused the request body before Laravel could use it.
3 causes, each with a fixBack end
Laravel routes return 404 or throw NotFoundHttpException
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
A 404 means Laravel found no route for that URL, or the request never reached Laravel at all.
3 causes, each with a fixBack end
Livewire uploads work locally but fail behind nginx on the server
$_POST and $_FILES are empty (PHP discards a body over post_max_size)
Three separate limits stop a large upload, and a local dev server hides two of them.
3 causes, each with a fixBack end
Your plain PHP endpoint sets CORS headers but the browser still blocks it
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/save.php:1)
The headers only help if they are sent on every response the browser looks at, starting with the OPTIONS preflight.
3 causes, each with a fix