简体   繁体   English

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

[英]ob_flush() working on localhost but not online at GoDaddy

I have the following PHP script: 我有以下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();
?>

It works fine on WAMP localhost and prints new line each second, but online at GoDaddy economy hosting, it doesn't work. 它在WAMP localhost上工作正常并且每秒打印新行,但是在GoDaddy经济主机上在线,它不起作用。 It shows the output after 10 seconds of nothing happens but the page loading. 它显示10秒后输出但没有发生但页面加载的输出。

What could be wrong? 可能有什么不对?

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM