PHP Flush/ob_flush not working

The idea here is to disable output buffering, not enable it. As its name says, output buffering will save the output to memory and display it at the end of the script, or when explicitly asked for it.

That being said, you don’t have to flush explicitly for every output. Use the following, before displaying any output, and then you won’t have to bother flushing every time you echo something:

ob_implicit_flush(true);
ob_end_flush();

Per example:

ob_implicit_flush(true);
ob_end_flush();

for ($i=0; $i<5; $i++) {
   echo $i.'<br>';
   sleep(1);
}

Will output, 0 to 4, with each being displayed every second.

Leave a Comment