How to check if a php script is still running(如何检查 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 脚本是否仍在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何检查 php 脚本是否仍在运行
基础教程推荐
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php中的foreach复选框POST 2021-01-01
- Web 服务器如何处理请求? 2021-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- php中的PDF导出 2022-01-01
