Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I don't have any problem on localhost. but when i tested my codes on server, end of every page i see this notice.

my code:

<?php
ob_start();
include 'view.php';

$data = ob_get_contents();
ob_end_clean();
include 'master.php';
ob_end_flush();  // Problem is this line
like image 683
AliN11 Avatar asked Aug 01 '16 08:08

AliN11


3 Answers

WordPress attempts to flush the output buffers on shutdown. It fails because you have already called ob_end_flush().

You should be able to keep compression on, and simply unhook the flush action:

remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 );

You can now call ob_end_flush() manually, and keep zlib compression on.

like image 112
alexg Avatar answered Nov 02 '22 11:11

alexg


I wouldn't recommend disabling the wp_ob_end_flush_all() function entirely, and I definitely wouldn't turn off zlib.output_compression in your php.ini file. Here's a better approach that replaces the source code causing the issue, and preserves the underlying functionality:

/**
 * 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 the cause, and why this is probably the best approach can be found here: Quick Fix for WordPress ob_end_flush() Error

like image 28
Kevin Leary Avatar answered Nov 02 '22 09:11

Kevin Leary


It solved when switched off zlib.output_compression in php.ini

zlib.output_compression = Off

like image 9
AliN11 Avatar answered Nov 02 '22 11:11

AliN11