[英]Can I run a CRON job for an hour
I am creating an app that requires a CRON job to be executed every 60 seconds. 我正在创建一个需要每60秒执行一次CRON作业的应用。
My host only allows a CRON job once an hour. 我的主机每小时仅允许一次CRON作业。
I was wondering if I could create a script like this: 我想知道是否可以创建这样的脚本:
$i = 0;
while(1==1){
// update database code
delay(10000);
// $i is incremented once a minute/10000ms
$i++;
}
//if $i reaches 60 we know that the CRON has run for an hour
if($i == 60){
die();
}
Is this recommended? 推荐这个吗? Will this accurately update my database every 60 seconds?
这会每60秒准确更新一次我的数据库吗?
I don't mind if the script will be a few seconds out. 我不介意该脚本是否需要几秒钟。
I understand I will need to set my php.ini
to increase the max execution time. 我了解我将需要设置
php.ini
以增加最大执行时间。
Should work, if the hosting allows overriding of max_execution_time
. 如果托管允许覆盖
max_execution_time
,则应该工作。 You can do it right in the script, by the way: ini_set('max_execution_time', 0)
. 您可以直接在脚本中执行以下操作:
ini_set('max_execution_time', 0)
。 And be careful with memory. 并注意存储。 It's not C/C++, of course, but still a good idea to watch variables initialization and loops.
当然,它不是C / C ++,但监视变量的初始化和循环仍然是一个好主意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.