在下面的代码中执行“echo ...”的两行上,我收到无法解释的“标题已在第 #... 行发送”错误。
案例简化版:
<?php
ob_start();
//Initializing FirePHP...
include_once(F_FS_PATH."lib/FirePHPCore/fb.php");
// <--- I've also tried to move the ob_start(), after the FirePHP init,
// <--- instead before it. But it made no difference.
?>
<html>
<div>A lots of HTML (and php) code goes here... Actually my entire page.
FirePHP is also used here many times by multiple invocations
of the function fb('debug text');</div>
</html>
<?php
$all_page_content=ob_get_clean();
if ($GLOBALS["marketing_enabled"])
echo marketingReplaceContent($all_page_content);
else
echo $all_page_content;
ob_flush(); flush();
//Do some other non-printing - but slow stuff.
do_the_silent_slow_stuff_Now();
// <--- presumably the php execution ends here.
?>
我不明白为什么 FirePHP 在打印缓冲区并刷新它后试图在页面完成时执行某些操作?或者说它在尝试什么?我该如何应对这个问题? :(
最佳答案
这是你的问题:
Headers already sent on line #...
这就是当您使用 FirePHP 并预先回显某些内容时会发生的情况。这甚至可能是 <?php
之前的空格。标签。 FirePHP 将其所有内容作为 header 发送,并且在进行任何输出后无法发送 header 。
因为我确定您在 do_the_silent_slow_stuff_Now();
中调用了 FirePHP我建议不要同时使用缓冲、刷新和FirePHP。
要么你在 ob_start()
上辞职和ob_flush()
在开发阶段或者您调用ob_flush()
所有事情完成后的方法。
第三种可能性是通过执行类似 $development = true;
的操作来分离您的开发阶段和实时阶段。并创建您自己的 FirePHP 函数:
function my_fb($text) {
if(!$development)
fb($text);
}
和:
if($development) {
do_the_silent_slow_stuff_Now();
ob_flush(); flush();
}
else {
ob_flush(); flush();
do_the_silent_slow_stuff_Now();
}
希望这有帮助!
关于php - 输出缓冲和 FirePHP 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6584477/