【问题标题】:Cannot use output buffering in output buffering display handlers不能在输出缓冲显示处理程序中使用输出缓冲
【发布时间】:2016-02-29 09:32:30
【问题描述】:

我重新安装了 Apache,并从 PHP 5.3 切换到 5.6。一切正常,除了我在调用ob_start() 时收到此错误:

Cannot use output buffering in output buffering display handlers

我尝试在 PHP 中启用输出缓冲,但仍然收到此错误:

output_buffering = 4096

【问题讨论】:

  • 你重启网络服务器了吗?
  • 当然。很多次
  • 使用过的 php.ini 的内存限制是多少,我认为如果将其设置为更高的值,它将起作用。
  • php.ini 中的 memory_limit?目前是 1024M
  • 应该够了!它是自定义网站还是 wordpress?

标签: php apache output-buffering ob-start


【解决方案1】:

您正在尝试在缓冲区回调中启动输出缓冲区。如果您使用此代码,它将生成该错误。但是如果你从回调函数中删除ob_start()就可以了。

<?php
error_reporting(-1);

function callback($buffer){
    //you can't call ob_start here
    ob_start();
    return (str_replace("apples", "oranges", $buffer));
}

ob_start("callback");

?>
<html>
<body>
<p>It's like comparing apples to oranges.</p>
</body>
</html>
<?php
ob_end_flush();

【讨论】:

    【解决方案2】:

    可能您在输出缓冲回调中使用了缓冲函数,如 php ob_start output_callback 文档中所述,这是不可能的。如果不是,它应该是您使用的输出处理程序,请检查您的 php.ini 并尝试将其值设置为“none”(如果可能)。

    【讨论】:

      【解决方案3】:

      也许这个示例代码可以帮助你:

      ob_start();
      echo "test";
      $content = ob_get_contents();
      ob_end_clean();
      var_dump($content);
      

      【讨论】:

        【解决方案4】:

        尽管这是一个老问题,但我只是想补充一点,当系统在缓冲时内存不足时也会发生同样的错误。

        如果是这种情况,本主题中提到的错误后面总是会出现Allowed memory size of xxx bytes exhausted 错误。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-09-11
          相关资源
          最近更新 更多