This is due to output buffering. If output buffering is enabled, the output is not immediately sent to the client, but will wait until a certain amount of data is buffered. This usually increases performance, but causes problems like yours.
A simple solution does not require changing any php.ini parameters, but just put this at the top of your script:
<?php while (@ob_end_flush()); ?>
This will immediately disable and disable all output buffering.
(Source: http://www.php.net/manual/en/function.ob-end-flush.php#example-460 )
You can also read the PHP manual on Output Control . The related php.ini settings are listed here .
If you want to make sure things are sent (i.e. before a time-consuming task), call flush() at the appropriate time.
Edit:
In fact, browsers can have their own buffers, especially when the Content-Type is not explicitly set (the browser needs to sniff the MIME file type). If so, you cannot control browser behavior.
One way to solve this problem is to explicitly specify the Content-Type:
header("Content-Type: text/plain");
But this is not guaranteed. It works on my Firefox, but not Chrome .
In any case, your final code should look like this:
header("Content-Type: text/html"); // Set Content-Type while (@ob_end_flush()); // Flush and disable output buffers while ($a++ < 5) { $b = 0; while ($b++ < 1015) { echo "H"; //flush(); // In fact because there is no significant delay, you should not flush here. } echo "<br><br>\n"; flush(); // Flush output sleep(1); }