如何最好地控制(向其发出命令信号)基于 PHP 的守护进程脚本?

发布于 2024-08-18 14:04:12 字数 591 浏览 2 评论 0原文

我创建了一个 PHP 守护程序脚本来持续监视服务器文件系统上特定目录中的新文件,然后处理并存档它们。

注意: 我正在使用php Daemon 类提供于:
http://www.phpclasses.org/browse /file/8958.html

我已经运行了脚本,但我需要一种与守护程序交互并发出命令的方法。例如,一个真正有用的命令是“停止”! :) 我目前必须手动终止该进程。

我在使用控制文件之前已经完成了此操作(即,检查文件中是否有新命令,如果存在则执行它,然后清除该文件)。我也使用过套接字,但这个问题并不真正需要任何网络。是否有更好、更优雅或更自然的方式向守护进程发送命令信号?

我确实找到了这个:
PHP 守护进程/worker 环境
但恐怕我不完全掌握如何使用提供的代码。

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.

Note: I'm using a php Daemon class provided at:
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 (i.e., 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
But I'm afraid I don't fully grasp how to use the provided code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一抹微笑 2024-08-25 14:04:13

一种可能的解决方案是使用信号 - 请参阅 pcntl_signal,例如:您的 PHP 守护进程将侦听信号,而您只需从“外部”发送信号。

这是 UNIX/Linux 上经常使用的一种方式——但请注意,pcntl_* 函数在 Windows 上不可用。 (您发布的类已经使用 pcntl* 函数,所以这里没有什么新内容)

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".

That's a way that is quite often used on UNIX/Linux -- but note that pcntl_* functions will not be available on windows. (The class you posted is already using pcntl* functions, so nothing new here)

瞳孔里扚悲伤 2024-08-25 14:04:13

在 *nix 上你可以使用信号来控制你的守护进程;请参阅pcntl_signal() 和 < code>signal(7) 手册页。

On *nix you can use signals to control your daemon; seepcntl_signal() and the signal(7) man page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文