2

我在下面的代码中执行“echo ...”的那 2 行出现无法解释的“标头已在 #... 行发送”错误。

案例的简化版:

<?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 会在页面完成后尝试做某事?或者它在尝试什么?我该如何应对这个问题?:(

4

1 回答 1

3

这是你的问题:

标头已在第 # 行发送...

这就是当您使用 FirePHP 并预先回显某些内容时会发生的情况。这甚至可能是<?php标签前的空格。FirePHP 将其所有内容作为header发送,并且在进行任何输出后无法发送 headers。

因为我确定你在你的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();
}

希望这可以帮助!

于 2011-07-05T14:51:30.130 回答