在下面的代码中,在执行"echo…"的那两行中,我得到了无法解释的"Headers already sended on line#…"错误。
案例的简化版本:
<?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试图在页面完成时做一些事情?或者它在尝试什么?我该如何处理这个问题?:(
这是您的问题:
标题已在第#行发送。。。
当您使用FirePHP并事先回显某些内容时,会发生这种情况。这甚至可能是<?php
标记之前的空白。FirePHP将其所有内容作为标头发送,并且在进行任何输出后都不能发送标头。
由于我确信您在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();
}
希望这能有所帮助!