[英]When does a PHP script stop executing when called from CLI?
I basically have a cron job calling one script every minute. 我基本上有一项计划工作,每分钟调用一个脚本。 Script immediately stops, if previous script is still running (checks previous script's activity time). 如果先前的脚本仍在运行,则脚本立即停止(检查先前的脚本的活动时间)。
So I made a bug, and the script went in to an infinite loop (I know it was called from by cron atleast one time). 因此我犯了一个错误,脚本进入了无限循环(我知道cron至少有一次调用过该脚本)。 I created a fix and uploaded it to the server, but I'm still wondering: 我创建了一个修复程序并将其上传到服务器,但是我仍然想知道:
The script just echo
es out the same text over and over again. 脚本只是一遍又一遍地echo
显相同的文本。
PS PHP's max execution time within the script is set to 0 (infinite) and I don't have a direct access to the server, only FTP. PS PHP在脚本中的最大执行时间设置为0(无限),我没有直接访问服务器的权限,只有FTP。
How can I know if it is still running? 我怎么知道它是否仍在运行?
Just set up a new cron job, but have the cron command be a something that helps you debug: a useful one would be 只需设置一个新的cron作业,但是让cron命令可以帮助您进行调试:一个有用的命令是
ps -af | grep php > /some/path/to/mylogfile.txt
the ps
command lists info on running processes. ps
命令列出有关正在运行的进程的信息。 with those flags, part of the output will be the original linux command that started the process, and so we can grep the line and look for php
because the origional command was probably something like: 带有这些标志,输出的一部分将是启动该过程的原始linux命令,因此我们可以grep这一行并查找php
因为origional命令可能类似于:
php myscript.php
the output is redirected to mylogfile.txt
for you to manually read after the cron job runs. 输出将重定向到mylogfile.txt
以便您在cron作业运行后手动读取。
the process id should be part of the output. 进程ID应该是输出的一部分。 you can then use the kill
command on that process id, again by just entering the command as a fake cron job. 您可以再次在该进程ID上使用kill
命令,只需将其作为伪cron作业输入即可。
max_execution_time
defined in php.ini file or set_time_limit method) 直到在脚本运行成超时( max_execution_time
在php.ini文件或参数或者set_time_limit方法定义) PS: you have to php.ini files - one for command line and one for Apache - be sure to Change the max_execution_time in the commandline ini file PS:您必须使用php.ini文件-一个用于命令行,一个用于Apache-确保在命令行ini文件中更改max_execution_time
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.