Is it possible to display string on the browser while in infinite loop? This is what I want to happen:
while(1) {
echo "should display these lines on browser while in infinite loop.<br>";
}
Is it possible to display string on the browser while in infinite loop? This is what I want to happen:
while(1) {
echo "should display these lines on browser while in infinite loop.<br>";
}
Add
flush()
after the echo statement, it will flush the output to the browser. Note that browsers generally don't start to render until their reach a certain amount of information (around .5kB).If you don't want to put flush(); after each echo of your code:
Set this in your php.ini:
Or if you don't have access to php.ini:
Yes, it is possible. You need to flush the output to the browser if you want it to appear immediately:
Chances are that whatever you're trying to accomplish, this isn't how you should go about it.
PHP will eventually time-out, but not before it generates a massive HTML document that your browser will have trouble displaying.
Notice the use of
ob_flush();
to make sure php outputs, andusleep(100000)
to have time to see things happening.