如何检查php脚本是否仍在运行 [英] How to check if a php script is still running

查看:256
本文介绍了如何检查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";

这篇关于如何检查php脚本是否仍在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆