简体   繁体   English

Shell:运行PHP脚本并等待其完成

[英]Shell: Run PHP script and wait for it to finish

I need to write shell script, which will run PHP script every x seconds. 我需要编写shell脚本,它将每x秒运行一次PHP脚本。 And I need to be sure, that previous execution has finished. 而且我需要确保先前的执行已经完成。

Is it possible to run PHP script from shell and (for example) wait for "done" message from PHP? 是否可以从外壳运行PHP脚本并(例如)等待来自PHP的“完成”消息?

what if the script dies and fails to return a "done" message? 如果脚本死了并且未能返回“完成”消息怎么办?

what if the script returns an error? 如果脚本返回错误怎么办?

There are any number of situations where this is probably not the optimal way to deal with your problem. 在许多情况下,这可能都不是解决问题的最佳方法。

You may be better off writing a process ID file (PID) when the script starts running. 当脚本开始运行时,最好编写一个进程ID文件(PID)。 using getmypid() 使用getmypid()

The when it is time to execute it again, check the PID file, if it is stale and the process has finished then run again, else exit without running as the old process is still active. 是时候再次执行它了,检查PID文件,如果它已过时并且进程已完成,然后再次运行,否则退出而不运行,因为旧进程仍处于活动状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM