Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display the output while looping in php

Tags:

php

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>";
}
like image 714
Neigyl R. Noval Avatar asked Nov 30 '22 07:11

Neigyl R. Noval


1 Answers

Yes, it is possible. You need to flush the output to the browser if you want it to appear immediately:

while(1) {
     echo "should display these lines on browser while in infinite loop.<br>";
     flush();
}

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.

like image 68
meagar Avatar answered Dec 06 '22 02:12

meagar