ob_flush()在localhost上工作但在GoDaddy没有在线工作

时间:2017-01-20 21:37:54

标签: php linux buffer flush server-configuration

我有以下PHP脚本:

<?php 
ob_end_flush();
ob_start();
for ($i=0; $i < 10; $i++) {
    echo "Line ".$i."</br>";
    ob_flush();
    flush();
    sleep(1);
}
ob_end_flush();
?>

它在WAMP localhost上工作正常并且每秒打印新行,但是在GoDaddy经济主机上在线,它不起作用。它显示10秒后输出没有任何反应,但页面加载。

可能出现什么问题?

1 个答案:

答案 0 :(得分:3)

It will work fine....

if(!ob_get_level()) ob_start();
echo json_encode(array('valid'=>true,'msg'=>'Flush occured.'));
$size = ob_get_length();
header("Content-Type: application/json");
// Set the content length of the response.
header("Content-Length: {$size}");
//Close the connection if you want to.
header("Connection: close");
// Flush all output.
ob_end_flush();
ob_flush();
flush();
// Close current session (if it exists).
if(session_id()) session_write_close();