strobic Posted December 30, 2010 Share Posted December 30, 2010 Hi, I am trying to loop a script every 10 seconds but am getting the following error: Fatal error: Maximum execution time of 60 seconds exceeded Part of the code is: <?php while (1) { echo "hello"; sleep(10); ob_flush; flush(); } ?> I have put echo "hello" just to test before adding the script. Is there a correct way to do this loop? also running this the page struggles and says it is still loading. Quote Link to comment https://forums.phpfreaks.com/topic/222998-problem-using-while-loop-and-delaying-with-sleep/ Share on other sites More sharing options...
johnny86 Posted December 30, 2010 Share Posted December 30, 2010 PHP is server side language and therefore as long as your script is running, the browser won't get a response. Your script runs over 60 seconds because you are in an infinite loop. Which means you will never send a response to the browser. You should use JavaScript for scripts like that. Quote Link to comment https://forums.phpfreaks.com/topic/222998-problem-using-while-loop-and-delaying-with-sleep/#findComment-1152991 Share on other sites More sharing options...
chronister Posted December 30, 2010 Share Posted December 30, 2010 <?php for($x = 0; $x < 10; $x++) { echo "hello"; sleep(10); ob_flush; flush(); } ?> This will stop the infinite loop and only allow this to run 10 times. Quote Link to comment https://forums.phpfreaks.com/topic/222998-problem-using-while-loop-and-delaying-with-sleep/#findComment-1153016 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.