Jump to content

Problem using while loop and delaying with sleep()


strobic

Recommended Posts

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.