通过执行exec()调用的时候长时间运行PHP脚本将停止,但完成时通过CLI称为 [英] Long running PHP script stops when called through exec(), but finishes when called through the CLI
问题描述
我有一大堆这需要很长的时间才能完成的脚本。他们中有些人可能需要长达20分钟。
I have a bunch of scripts which take a long time to complete. Some of them can take up to 20 minutes.
有一个Bash脚本,其执行这些PHP脚本。当我把这个Bash脚本通过CLI为根,所有的PHP脚本完成,没有任何问题。但是,当我打电话Bash脚本与PHP的EXEC()通过浏览器功能,脚本突然7/8分钟后停止不抛出任何错误。
There's a Bash script which executes these PHP scripts. When I call this Bash script through the CLI as root, all the PHP scripts finish without any problems. But when I call the Bash script with PHP's exec() function through the browser, the scripts suddenly stop after 7/8 minutes without throwing any errors.
有一定的限制,到时候通过Apache / PHP执行的过程或脚本可以运行?
Is there a certain restriction to the time a process or script can run when executed through Apache/PHP?
我试过:
-
参数或者set_time_limit(0)
-
EXEC('的nohup /路径/要/ bashscript')
-
EXEC('/路径/要/ bashscript |在现在')
set_time_limit(0)
exec('nohup /path/to/bashscript')
exec('/path/to/bashscript | at now')
最后两个试图解决方案已经通过推荐其他人谁曾与长时间运行脚本的问题,但它并不能帮助我。
The last two tried solutions have been recommended by others who have had problems with long running scripts, but it doesn't help me at all.
注意:
它执行PHP脚本的Bash脚本是CakePHP的控制台应用程序。我通过这个Bash脚本执行PHP脚本使用的CakePHP的所有功能(机型,外壳方法等)。我需要能够通过浏览器调用Bash脚本,并让它在后台运行。
Note: The Bash script which executes the PHP scripts is CakePHP's console app. I have to execute the PHP scripts through this Bash script to make use of all the functionality of CakePHP (models, shell methods, etc). And I need to be able to call the Bash script through the browser, and let it run in the background.
服务器是VPS并安装WHM /的cPanel。
The server is a VPS and has WHM/cPanel installed.
推荐答案
您需要使用增加最大执行时间(小心,而设置为0,它会让你的执行时间是无限的)
you need to increase max execution time using (Careful while setting 0, it makes your execution time infinite)
ini_set('max_execution_time', 0);
但我会建议用户
proc_open();
在EXEC();
这将管你的流程,你可以阙其他进程。读
更多关于proc_open [这里] HTTP://www.sitepoint。 COM / proc中,开放式沟通,用最外面世界/ !
这篇关于通过执行exec()调用的时候长时间运行PHP脚本将停止,但完成时通过CLI称为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!