Ob_flush不能在新的apache配置上工作


ob_flush not working on new apache configuration

我最近从Amazon Elastic Beanstalk迁移到我自己的ubuntu 14.04 lts服务器。除了一个使用ob_flush并继续进行处理的页面外,所有内容都顺利移植了。下面是这段代码:

 <?php 
 //put string of page ----> $string
 ob_end_clean();
 header("Connection: close");
 ignore_user_abort(true); // optional
 ob_start();
 echo ($string);
 $size = ob_get_length();
 header("Content-Length: $size");
 ob_end_flush(); // Strange behaviour, will not work
 flush();            // Unless both are called !
 session_write_close(); // Added a line suggested in the comment
 // Do processing here
sleep(10);
//do stuff
echo "something";

我希望打印$string的内容,而不是$string的内容,然后打印"某事"。在这个代码片段中,"something"仍然会输出。我禁用了mod_pagesed(目前是启用的),并确保gzip和缓冲区输出设置为关闭。

这是我的php.ini文件(我有它离线,因为它是完整的,可能不相关的问题)。我还怀疑这可能与我的apache配置文件有关,您可以在这里看到。最后,如果这与我的问题有关,这里有一个链接到我的页面速度配置。当我调用该函数时,错误日志显示没有错误,另外我有对服务器的根访问权限。谢谢你帮我解决这个问题!

杰克叶

我认为你是混淆ob_get_contents和ob_end_flush见:http://php.net/manual/en/function.ob-start.php.