php 注意: ob_end_flush(): 未能在 zlib 输出压缩 (1) 中发送缓冲区
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38693992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Notice: ob_end_flush(): failed to send buffer of zlib output compression (1) in
提问by AliN11
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
采纳答案by AliN11
It solved when switched off zlib.output_compression in php.ini
它在关闭 zlib.output_compression 时解决了 php.ini
zlib.output_compression = Off
zlib.output_compression = Off
回答by alexg
WordPress attempts to flush the output buffers on shutdown. It fails because you have already called ob_end_flush()
.
WordPress 尝试在关闭时刷新输出缓冲区。它失败了,因为您已经调用了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.
您现在可以ob_end_flush()
手动调用,并保持 zlib 压缩。
回答by Kevin Leary
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:
我不建议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() );
} );
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
有关原因的更多详细信息以及为什么这可能是最佳方法,请参见此处:快速修复 WordPress ob_end_flush() 错误
回答by Adambean
I found a particular plug-in was the cause on one of our client's WP sites.
我发现一个特定的插件是我们客户的一个 WP 站点上的原因。
In this case it was caused by the "NextGEN Gallery" plug-in, but weirdly simply deactivating and then activating the plug-in resolved the issue.
在这种情况下,它是由“NextGEN Gallery”插件引起的,但奇怪的是,只需停用然后激活插件即可解决问题。
For anyone else having this problem it would be worth looking for suspect front end facing plug-ins and trying the same. If you find that the issue comes back when the culprit plug-in is reactivated you should file an issue with the plug-in author.
对于遇到此问题的其他任何人,值得寻找可疑的面向前端的插件并尝试相同的方法。如果您发现在重新激活罪魁祸首插件后问题再次出现,您应该向插件作者提交问题。
回答by Obewan
You Should always disable front-facing errors on live sites for security reasons - regardless.
出于安全原因,您应该始终禁用实时站点上的正面错误 - 无论如何。
If you want to hide the errors in Wordpress and get a log of the errors for review instead, you can do something like the following in your wp-config.php file:
如果您想隐藏 Wordpress 中的错误并获取错误日志以供,您可以在 wp-config.php 文件中执行以下操作:
// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );
// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
PS: If you want to use the remove_action code by alexg above, remove_action('shutdown', 'wp_ob_end_flush_all', 1);
you will need to place it in the functions.php file of your theme.
PS:如果你想使用上面alexg的remove_action代码,remove_action('shutdown', 'wp_ob_end_flush_all', 1);
你需要把它放在你主题的functions.php文件中。
PPS: You may also want to try using define(‘WP_MEMORY_LIMIT','1024M');
in your wp-config.php file - however, be careful that you don't allocate more than you need to as this affects the front end of Wordpress and you'll run the risk of running out of RAM if you have too many simultaneous hits on pages.
PPS:您可能还想尝试define(‘WP_MEMORY_LIMIT','1024M');
在您的 wp-config.php 文件中使用 - 但是,请注意不要分配超过您需要的数量,因为这会影响 Wordpress 的前端,并且您将面临运行的风险如果页面上同时点击过多,则内存不足。
回答by Vivek Athalye
One another scenario:
另一种场景:
I was getting this notice on my live site but not on localhost and a staging / demo site, even though the demo site was on the same server as live site.
我在我的实时站点上收到此通知,但在本地主机和临时/演示站点上没有收到此通知,即使演示站点与实时站点位于同一台服务器上。
It turned out that zlib extension wasn't activated on live site and it was causing the notice. Once the zlib extension was activated, the notice stopped coming. So there was no code fix needed.
事实证明,zlib 扩展未在实时站点上激活,并且导致了该通知。一旦 zlib 扩展被激活,通知就停止了。所以不需要代码修复。
回答by John Nguy?n
Try to disable wordpress debug mode and it's resolved.
You can disable WP debug mode in /wp-config.php
:
尝试禁用 wordpress 调试模式并解决。您可以在/wp-config.php
以下位置禁用 WP 调试模式:
define('WP_DEBUG', FALSE);