如何检查 php 脚本是否仍在运行
我有一个侦听队列的 PHP
脚本.从理论上讲,它永远不会死.有什么东西可以检查它是否还在运行?Ruby's God (http://god.rubyforge.org/)
之类的东西用于 PHP
?
I have a PHP
script that listens on a queue. Theoretically, it's never supposed to die. Is there something to check if it's still running? Something like Ruby's God ( http://god.rubyforge.org/ )
for PHP
?
上帝是语言不可知论者,但如果有一个也适用于 Windows 的解决方案,那就太好了.
God is language agnostic but it would be nice to have a solution that works on windows as well.
推荐答案
我遇到了同样的问题 - 想检查脚本是否正在运行.所以我想出了这个,并将它作为一个 cron 作业运行.它将正在运行的进程作为一个数组抓取并循环遍历每一行并检查文件名.似乎工作正常.将 #user# 替换为您的脚本用户.
I had the same issue - wanting to check if a script is running. So I came up with this and I run it as a cron job. It grabs the running processes as an array and cycles though each line and checks for the file name. Seems to work fine. Replace #user# with your script user.
exec("ps -U #user# -u #user# u", $output, $result);
foreach ($output AS $line) if(strpos($line, "test.php")) echo "found";
相关文章