开发者

How to make a script launched by cron to sleep for X seconds?

开发者 https://www.devze.com 2023-02-19 00:30 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号