[英]How best to control (issue command signals to) a PHP-based Daemon script?
I've created a PHP Daemon script to continually monitor a particular directory on the server's file system for new files, and then process and archive them. 我已经创建了一个PHP守护程序脚本来持续监视服务器文件系统上的特定目录以获取新文件,然后处理和归档它们。
Note: I'm using a php Daemon class provided at:
注意:我正在使用提供的php Daemon类:
http://www.phpclasses.org/browse/file/8958.html http://www.phpclasses.org/browse/file/8958.html
I've got the script running, but I need a way to interface with the daemon and issue commands. 我已经运行了脚本,但是我需要一种与守护进程交互并发出命令的方法。 One really useful command, for instance, would be "STOP"!
例如,一个非常有用的命令就是“停止”! :) I currently have to kill the process manually.
:)我目前必须手动杀死进程。
I've done this before using control files (ie, check the file for a new command, execute it if one exists, then clear the file). 我在使用控制文件之前已经这样做了(例如,检查文件是否有新命令,如果存在则执行它,然后清除文件)。 I've also used sockets, but this problem doesn't really call for any networking.
我也使用了套接字,但这个问题并没有真正需要任何网络。 Is there a better, more elegant or natural way to send command signals to the Daemon?
是否有更好,更优雅或更自然的方式向守护进程发送命令信号?
I did find this: 我确实发现了这个:
PHP Daemon/worker environment PHP守护进程/工作者环境
But I'm afraid I don't fully grasp how to use the provided code. 但我担心我没有完全掌握如何使用提供的代码。
A possible solution would be to use signals -- see pcntl_signal
, for instance : your PHP daemon would listen for signals, and you'd only have to send signals from "outside". 一个可能的解决方案是使用信号 - 例如,参见
pcntl_signal
:你的PHP守护进程会监听信号,你只需要从“外部”发送信号。
That's a way that is quite often used on UNIX/Linux -- but note that pcntl_*
functions will not be available on windows. 这是在UNIX / Linux上经常使用的一种方式 - 但请注意,
pcntl_*
函数在Windows上不可用。 (The class you posted is already using pcntl*
functions, so nothing new here) (你发布的课程已经使用了
pcntl*
函数,所以这里没什么新东西)
On *nix you can use signals to control your daemon; 在* nix上,您可以使用信号来控制您的守护进程; see
pcntl_signal()
and the signal(7)
man page. 请参阅
pcntl_signal()
和signal(7)
手册页。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.