Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Disable zlib.output_compression on WordPress : Notice: ob_end_flush(): failed to send buffer of zlib output compression (1) in /path/wp-includes/functions.php on line 3282 via https://core.trac.wordpress.org/ticket/18525
SOLUTIONS I have came across so far:
======================== SOLUTION 1 ====================
In plugins (or somewhere) you probably have this code:
ini_set('zlib.output_compression', '1');
so, I replaced that code with
if (!is_admin()) ob_start('ob_gzhandler'); //because, in admin pages, it causes plugin installation freezing
and Compression will be remained still ON.
======================== SOLUTION 2 ====================
You may have to use:
remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 );
======================== SOLUTION 3 via @Kevinlearynet ====================
/**
* Proper ob_end_flush() for all levels
*
* This replaces the WordPress `wp_ob_end_flush_all()` function
* with a replacement that doesn't cause PHP notices.
*/
remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 );
add_action( 'shutdown', function() {
while ( @ob_end_flush() );
} );
@Kevinlearynet
Copy link

Kevinlearynet commented Dec 11, 2019

Solution 3

/**
 * Proper ob_end_flush() for all levels
 *
 * This replaces the WordPress `wp_ob_end_flush_all()` function
 * with a replacement that doesn't cause PHP notices.
 */
remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 );
add_action( 'shutdown', function() {
   while ( @ob_end_flush() );
} );

More details on why this is the best option can be found here:

I hope this helps!

@loorlab
Copy link
Author

loorlab commented Dec 12, 2019

@Kevinlearynet Great !

Thanks !

@mdmoniruzzaman83
Copy link

mdmoniruzzaman83 commented Feb 28, 2020

Yes, it is worked very fine. Thank you for your solution.

@loorlab
Copy link
Author

loorlab commented Feb 28, 2020

@mdmoniruzzaman83 yeah !

Yes, it is worked very fine. Thank you for your solution.

@iswadhin
Copy link

iswadhin commented Mar 30, 2021

Solution 3

/**
 * Proper ob_end_flush() for all levels
 *
 * This replaces the WordPress `wp_ob_end_flush_all()` function
 * with a replacement that doesn't cause PHP notices.
 */
remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 );
add_action( 'shutdown', function() {
   while ( @ob_end_flush() );
} );

More details on why this is the best option can be found here:

I hope this helps!

Hi @Kevinlearynet,

Thanks for the solution. I was just curious, does this solution actually solve the issue or is it something that just hides the error. If it just hides the error or is a quick fix, what do we need to do to solve this issue from the root. :)

Thanks again,
-Swadhin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment