PHP set_time_limit限制 [英] PHP set_time_limit limit

查看:164
本文介绍了PHP set_time_limit限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

QUESTION

如果我使用 sleep(300);

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

这意味着 set_time_limit(86400); 工作?

This means, would set_time_limit (86400); work?

然后我可以将我的主机时间表设置为每24小时使用一次。

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

INFO

发现我现在在做什么这个问题并且现在使用它每5分钟做一些事情。它工作得很好,准时,甚至秒正确。 (谈论每个 sleep 之间的差距) - 它睡3次,然后从我的主机的schedular再次调用。

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.

我有一个计划的任务设置在我的主机每15分钟,问题是这不是每(精确)15分钟发生,但更像是16和一个几分钟 - 几个小时后它是完全失去同步

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.

如果可以使用它在24小时内不退出,那么我可以调整代码中的睡眠,使其每5分钟执行一次。

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.

推荐答案

这是一个没有循环, sleep

如果使用 set_time_limit(0); ,代码将永远超时并永远运行,除非它先退出。例如,我在PHP中的 while(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通常是准确的。如果你的主机的cron是这样不同步,你应该联系他们,并询问它 - 这不正常。

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.

编辑:此外,你可能想考虑永远运行它并手动启动它,然后有一个cron任务,检查它是否仍然运行,如果不是,重新启动它。

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.

这篇关于PHP set_time_limit限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆