I 'm improving a cron job which loops a lot of stuff and updates my database. I would like to make ut wait, let's say 30 seconds every 100 requests.
Something like:
loop{
loop{
query();
}
wait(3000); // wait 3 seconds and continue
}
Can I do that?开发者_如何学运维 If so, is it possible the the cron job times out?
Thanks!
To make a configurable pause, use the sleep
function.
When launching PHP from the command line (as cron
does), the max_execution_time
is infinite by default, so you won't have to worry about timeouts unless you change it yourself.
You can set execution time limit to infinity with this:
set_time_limit(0);
And then you can use sleep()
function to pause the execution.
See the sleep()
function. It lets you wait for X seconds.
PS: you may need to also use set_time_limit()
.
// sleep for 10 seconds
sleep(10);
Use sleep.
精彩评论