输出缓冲和 FirePHP 错误
在下面的代码中执行“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是你的问题:
这正是当您使用 FirePHP 并预先回显某些内容时发生的情况。这甚至可能是
标记之前的空格。 FirePHP 将其所有内容作为 标头 发送,并且在进行任何输出后无法发送标头。
因为我确信您在
do_the_silent_slow_stuff_Now();
方法中调用了 FirePHP,所以我建议不要同时使用缓冲、刷新和 FirePHP。您可以在开发阶段退出
ob_start()
和ob_flush()
方法,或者在所有工作完成后调用ob_flush()
方法。第三种可能性是通过执行类似
$development = true;
的操作来分离您的开发和运行阶段,并创建您自己的 FirePHP 函数:并且:
希望这会有所帮助!
Here's your problem:
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()
andob_flush()
during the development phase or you call theob_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:and:
Hope this helps!