Skip to content

Instantly share code, notes, and snippets.

@loorlab
Last active March 30, 2021 12:35
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save loorlab/028d9fca02e6e4f85d1a to your computer and use it in GitHub Desktop.
Save loorlab/028d9fca02e6e4f85d1a to your computer and use it in GitHub Desktop.
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

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

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

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