php - Echo 'string' while every long loop iteration (flush() not working) -
i have loop takes long execute, , want script display whenever loop iteration done.
echo "hello!"; flush(); for($i = 0; $i < 10; $i ++) { echo $i; //5-10 sec execution time flush(); }
this not display echos until entire script completed. went wrong?
from php manual:
flush() may not able override buffering scheme of web server , has no effect on client-side buffering in browser. doesn't affect php's userspace output buffering mechanism. means have call both ob_flush() , flush() flush ob output buffers if using those.
echo "hello!"; flush(); ob_flush(); for($i = 0; $i < 10; $i ++) { echo $i; //5-10 sec execution time flush(); ob_flush(); }
-or- can flush , turn off buffering
<?php //flush (send) output buffer , turn off output buffering while (ob_get_level() > 0) ob_end_flush(); echo "hello!"; for($i = 0; $i < 10; $i ++) { echo $i . "\r\n"; } ?>
Comments
Post a Comment