问题描述
我有一个网站在我的webhotel我想运行一些计划任务。
I have a site on my webhotel I would like to run some scheduled tasks on. What methods of achieving this would you recommend?
到目前为止,我想到的是在每个页面的顶部都有一个脚本,然后让这个脚本检查是否
What I’ve thought out so far is having a script included in the top of every page and then let this script check whether it’s time to run this job or not.
这只是我在想的一个简单的例子:
This is just a quick example of what I was thinking about:
if ($alreadyDone == 0 && time() > $timeToRunMaintainance) {
runTask();
$timeToRunMaintainance = time() + $interval;
}
还有什么我应该考虑或有更好的方法吗?
Anything else I should take into consideration or is there a better method than this?
推荐答案
这就是cronjobs。 man crontab
假设您正在运行Linux服务器。如果你没有shell访问或没有办法设置cronjobs,有免费的服务,在外部服务器上设置cronjobs并ping你的一个URL。
That's what cronjobs are made for. man crontab
assuming you are running a linux server. If you don't have shell access or no way to setup cronjobs, there are free services that setup cronjobs on external servers and ping one of your URLs.
这篇关于PHP:运行计划作业(cron作业)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!