How to echo output in real time, (before script finishes)?
How do i output to the browser before the script finishes executing?
For example, the code below will output all 10开发者_Go百科0 "hi" at once, how do I make it so it will output as soon as that section of code is read/processed? For example: PHPBB3 forum shows installing process step by step.
<?php
for ($i = 0; $i <= 100; $i++) {
echo "hi";
echo "<br>";
}
?>
Call ob_implicit_flush() before your loop.
Note that this is not a guarantee (web server buffers, proxy buffers and web browsers who refuse to rerender are your enemy). It MAY help to echo some linefeeds (\n) as I seem to remember that there are browsers who will not rerender until they received a complete line.
This will not work at all if you use output buffering (e.g. for compression using gzip (if the gzip modul you use uses buffering which is not uncommon) or other reasons).
精彩评论