注意:ob_end_flush():在zlib输出压缩(1)的缓冲区发送失败。

32

我的本地主机上没有任何问题,但当我在服务器上测试我的代码时,每个页面的末尾都会显示这个通知。

我的代码:

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

$data = ob_get_contents();
ob_end_clean();
include 'master.php';
ob_end_flush();  // Problem is this line
13个回答

0

将此处的ob_end_flush()替换为remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 )

**
* Flush all output buffers for PHP 5.2.
*
* Make sure all output buffers are flushed before our singletons are destroyed.
*
* @since 2.2.0
*/
function wp_ob_end_flush_all() {
     $levels = ob_get_level();
     
     for ( $i = 0; $i < $levels; $i++ ) {
         ob_end_flush();
     }
}

更新后的代码应该是这样的
function wp_ob_end_flush_all() {
    $levels = ob_get_level();

    for ( $i = 0; $i < $levels; $i++ ) {
        remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 );
    }
}

-1

不要惊慌,这很简单。只需打开 PHP 函数并找到此代码即可

**
 * Flush all output buffers for PHP 5.2.
 *
 * Make sure all output buffers are flushed before our singletons are destroyed.
 *
 * @since 2.2.0
 */
function wp_ob_end_flush_all() {
  $levels = ob_get_level();
  for ( $i = 0; $i < $levels; $i++ ) {
    ob_end_flush();
  }
}

在你删除了"ob_end_flush();"代码之后,只需替换为下面的代码

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

问题已解决,百分之百完成。


1
编辑核心文件是个极坏的想法。 - Burgi
编辑核心文件并不是大多数人的理想解决方案。编辑后的文件将在下一次核心更新时恢复原状。编辑核心文件还可能在安装的其他区域引入副作用问题。https://wordpress.org/support/article/editing-files/#editing-files-offline - Mission Mike
修改核心文件是业余级别的解决方案,不是一个有效的修复方法,因为下一个WordPress版本将会默默地覆盖该修复。上面提供的其他解决方案都很好;最好使用remove_action函数来终止WordPress的不必要的end_flush功能。 - Brian C

-10
尝试禁用WordPress调试模式,问题就解决了。 您可以在/wp-config.php中禁用WP调试模式:
define('WP_DEBUG', FALSE);

3
听 @Casper 说的没错。这可能会更糟,因为你可能只会得到一个白屏,而不知道出了什么问题,尤其是 HTTP OK [200] 响应。调试模式应该一直开着,直到问题解决,然后再关闭。 - Adambean
在这种特定情况下,是一个不好的想法。然而,安装全新的WP 5.4.1并像任何开发人员一样定义('WP_DEBUG',true)会给我关于zlib.output_compression的错误。将其设置为false可以消除错误。 - Adrian P.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接