简体   繁体   English

从CLI调用时,PHP脚本何时停止执行?

[英]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: 我创建了一个修复程序并将其上传到服务器,但是我仍然想知道:

  1. How long will the bugged script run? 错误的脚本将运行多长时间?
  2. How can I know if it is still running? 我怎么知道它是否仍在运行?
  3. What does terminate a script and why? 什么终止脚本,为什么?

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作业输入即可。

  1. Until the script runs into an timeout( max_execution_time defined in php.ini file or set_time_limit method) 直到在脚本运行成超时( max_execution_time在php.ini文件或参数或者set_time_limit方法定义)
  2. Have a look at the running processes 看看正在运行的过程
  3. send kill command to the script or wait till a timeout occurs 将kill命令发送到脚本或等待超时

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.

相关问题 从浏览器调用PHP脚本失败但从CLI调用失败 - PHP script fails when called from a browser but not from CLI 从 Windows 10 XAMPP 执行 PHP CLI 脚本时未定义 $argv - $argv not defined when executing PHP CLI script from Windows 10 XAMPP 从PHP脚本调用时,CasperJS在Cron中不起作用 - CasperJS does not work in Cron when called from PHP script 当有人从命令行关闭执行php脚本时,是否有一个函数会被调用? - Is there a function which gets to be called when somebody closes executing php script from command line? 当使用 eval() 从 php 脚本调用脚本以及从 bash 脚本调用相同的函数时,python 如何使用路径? - How does python use paths when a script is called using eval() from a php script and when the same function is called from a bash script? 从 cron 作业调用时,为什么 PHP_SAPI 不等于“cli”? - Why does PHP_SAPI not equal 'cli' when called from a cron job? 通过exec()调用时,长时间运行的PHP脚本会停止,但在通过CLI调用时会结束 - Long running PHP script stops when called through exec(), but finishes when called through the CLI 退出HTML页面时,停止在PHP文件中调用的Python脚本 - Stop a Python Script called in a PHP File when HTML page is exited 从浏览器调用PHP exec失败但从CLI调用失败 - PHP exec fails when called from a browser but not from CLI 在CLI和node.js脚本中运行时,执行PHP脚本会产生不同的结果 - Executing PHP script has different results when run in CLI and by node.js script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM