我在localhost上没有任何问题.但是当我在服务器上测试我的代码时,每一页的末尾都会看到这个通知.
我的代码:
<?php
ob_start();
include 'view.php';
$data = ob_get_contents();
ob_end_clean();
include 'master.php';
ob_end_flush(); // Problem is this line
Run Code Online (Sandbox Code Playgroud)
Kev*_*ary 25
我不建议wp_ob_end_flush_all()完全禁用该功能,而且我绝对不会zlib.output_compression在您的php.ini文件中关闭。这是替换导致问题的源代码并保留底层功能的更好方法:
/**
* 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() );
} );
Run Code Online (Sandbox Code Playgroud)
有关原因的更多详细信息以及为什么这可能是最佳方法,请参见此处:快速修复 WordPress ob_end_flush() 错误
ale*_*exg 23
WordPress尝试在关机时刷新输出缓冲区.失败是因为你已经打过电话ob_end_flush().
您应该能够继续压缩,只需取消挂起刷新操作:
remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 );
Run Code Online (Sandbox Code Playgroud)
您现在可以ob_end_flush()手动调用,并保持zlib压缩.
它在关闭zlib.output_compression时解决了 php.ini
zlib.output_compression = Off