如何检查 php 脚本是否仍在运行

How to check if a php script is still running(如何检查 php 脚本是否仍在运行)
本文介绍了如何检查 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 脚本是否仍在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)