Flushing the output buffer doesn’t works in PHP sometimes no matter what you do. I had this code which would never work on my server but would perfectly fine on localhost. This was the code.
<?php
include('common.php');
ini_set('output_buffering','on');
ini_set('zlib.output_compression', 0);
//ini_set('implicit_flush',1);
ob_implicit_flush();
for($i=0;$i<10;$i++) {
echo $i;
echo str_repeat(" ", 500);
ob_flush();
flush();
sleep(1);
}
?>
I knew this had to do with Server configuration as the php code was fine. Then after searching a lot I stumbled across a page where it said that my host had recently enabled gzip for all pages, I instantly knew this was the problem.
So I made a .htaccess file in the folder where this script was and entered the following:
SetEnv no-gzip dont-vary
Saved the file. And it started buffering.
Cheers!