PHP set_time_limit limit

随声附和 提交于 2019-12-23 21:09:48

问题


QUESTION

Would it work fine if I use sleep(300); to do a whole day (24 hours) in 5-minute gaps?

This means, would set_time_limit (86400); work?

Then I can set my host's schedule to only be used once every 24 hours.


INFO

I found what I am doing now on this question and am now using it to do something every 5 minutes. It works well and is on time with even the seconds correct. (Talking about the gap between each sleep) - it sleeps 3 times and then gets called again from my host's-schedular.

I have a scheduled task set up at my host for every 15 minutes, problem is this is not happening every (precise) 15 minutes, but more like 16 and a bit minutes - and after a few hours it is totally out of sync.

If it's possible to use it to not quit within 24hrs, then I can adjust the sleep in the code to make it execute exactly every 5 mins.


UPDATE

17:17:50 22-09-2011 Check done!
17:34:09 22-09-2011 Check done!
17:47:47 22-09-2011 Check done!

I ran a script that appended to a file the date and "Check done!" - this was without a loop and sleep and that is what I got.


回答1:


If you use set_time_limit(0);, the code will never time out and run forever unless it exits first. For instance I write programs in PHP in a while(1) { ... } loop. It ran for about two weeks straight (then I had to restart my computer for some unrelated reason).

Cron is usually accurate though. If your host's cron is so out of sync, you should contact them and ask about it - that's not normal.

EDIT: Also, you might want to consider running it forever and start it manually, then having a cron task that checks if it's still running, and restart it if it isn't.




回答2:


would set_time_limit (86400); work?

Yes.

But don't do that if you run your script through a web server, this would occupy a connection during this whole time.



来源:https://stackoverflow.com/questions/7518439/php-set-time-limit-limit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!