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 脚本是否仍在运行
基础教程推荐
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何替换eregi() 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
