永远让PHP脚本循环从队列系统执行计算作业 [英] Having a PHP script loop forever doing computing jobs from a queue system

查看:112
本文介绍了永远让PHP脚本循环从队列系统执行计算作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我有一个永久运行在服务器上的perl脚本,它在SQS中检查要计算的数据.该脚本已经运行了大约6个月,没有任何问题.

Currently I have a perl script that runs forever on my server, checking a SQS for data to compute. This script has been running for about 6 months with no problems what so ever.

所以,现在我想切换到PHP的CLI,并在那里永久地执行脚本循环.主要是因为我对PHP更熟悉.

So, now I want to switch over to PHP'S CLI, and have the script loop there forever. Mostly because I'm more familiar with PHP.

基本上,

$i="forever";
while($i==="forever"){
    doSomething();
    sleep(10);
}

该脚本将执行一个shell_exec("/shell_script.sh");最多可能需要2个小时来处理.这会触发最大执行时间或类似的执行时间吗?

The script will do a shell_exec("/shell_script.sh"); that can take up to 2 hours to process. Will this trigger a max execution time or similar?

这可以吗?如果没有,有什么替代方案?

Is this "ok" to do? If not, what is the alternatives?

推荐答案

您将需要确保将脚本的最大执行时间设置为零,以便不施加时间限制.您可以使用以下命令从PHP文件中完成此操作:

You will need to make sure that you set the maximum execution time of the script to zero, so that no time limit is imposed. You can do this from the PHP file with,

set_time_limit(0);

或者您可以在php.ini文件中进行设置. (有关更多信息,请参见 set_time_limit 上的PHP手册).除此之外,您的方法应该可以正常工作.

Or you can set it in your php.ini file. (See PHP manual on set_time_limit for more information). Other than that, your approach should work fine.

但是,无需设置变量并对其进行检查以使其永远循环,

However, there's no need to set a variable and check it in order to loop forever,

$i="forever";
while($i==="forever")

您只需执行while(true)while(1).

这篇关于永远让PHP脚本循环从队列系统执行计算作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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