输出缓冲和 FirePHP 错误

发布于 2024-11-18 19:25:31 字数 951 浏览 4 评论 0原文

在下面的代码中执行“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 在打印缓冲区并刷新它后试图在页面完成时执行某些操作?或者说它在尝试什么?我该如何应对这个问题? :(

I get unexplained "Headers already sent on line #..." error on those 2 lines that execute "echo ..." in the code below.

Simplified version of the case:

<?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.
?>

I cannot understand why FirePHP is trying to do something upon page completion after I print the buffer and flushed it? Or what is it trying? How can I cope with this problem? :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

护你周全 2024-11-25 19:25:31

这是你的问题:

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

这正是当您使用 FirePHP 并预先回显某些内容时发生的情况。这甚至可能是 标记之前的空格。 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();
}

希望这会有所帮助!

Here's your problem:

Headers already sent on line #...

Thats exaclty what happens when you use FirePHP and echo something beforehand. This might even be a whitespace before the <?php tag. FirePHP sends all its content as a header, and headers can't be send after any output is made.

Since I'm sure that you call FirePHP in your do_the_silent_slow_stuff_Now(); method I recommend not to use buffering, flushing and FirePHP at once.

Either you resign on ob_start() and ob_flush() during the development phase or you call the ob_flush() method after all stuff is done.

Third possibility would be to seperate your development and live phase by doing something like $development = true; and make your own FirePHP function:

function my_fb($text) {
    if(!$development)
        fb($text);
}

and:

if($development) {
    do_the_silent_slow_stuff_Now();
    ob_flush(); flush();
}
else {
    ob_flush(); flush();
    do_the_silent_slow_stuff_Now();
}

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文