1

I have the following PHP script:

<?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. It shows the output after 10 seconds of nothing happens but the page loading.

What could be wrong?

MahmutTariq
  • 217
  • 1
  • 4
  • 17

1 Answers1

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();
RahulD
  • 729
  • 5
  • 8