php - 不能在输出缓冲显示处理程序中使用输出缓冲

标签 php apache output-buffering ob-start

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

Cannot use output buffering in output buffering display handlers

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

output_buffering = 4096

最佳答案

您正在尝试在缓冲区回调中启动输出缓冲区。如果您使用此代码,它将生成该错误。但是,如果您从回调函数中删除 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();

关于php - 不能在输出缓冲显示处理程序中使用输出缓冲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33936067/

相关文章:

php - 制作像 mega.nz 这样的侧边栏菜单

php - symfony2 命令中的自定义独白日志记录 channel

javascript - 在 foreach 语句的数组中包含空值

Apache:在后台重写 URL

php - SQLSRV PHP for SQL Server 不是有效的 Win32 应用程序

apache - 将 www.example.com 重写为 www.example.com/folder (无重定向)

php - 如何在 Perl 中缓存和清除输出缓冲区?

php - 我的 php 代码不会将用户添加到 MySQL 数据库

php - 在 Zend Framework 中渲染页面头部后刷新缓冲区

PHP ob_start() 问题