在php中向守护进程发送信号
我有一个用 PHP 编写的守护进程,它在我的 Linux 机器上运行。
我正在尝试通过另一个 php 文件向它发送信号。 为此,我正在尝试 posix_kill 函数。但它不起作用。
当我运行 php 页面时,出现错误,提示 php 编译时没有 --enable-grep
我想知道如何启用它?或者向守护进程发送信号的替代方法是什么?
I have a daemon written in PHP which is running on my linux machine.
I am trying to send a signal to it through another php file.
For this purpose I am trying posix_kill function. But its not working.
When I run the php page, I get an error that php is compiled without --enable-grep
I want to know how to enable it? OR what is the alternate way of sending signal to daemon?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
处理 PHP 脚本信号的唯一方法是使用 PCNTL 库重新编译 PHP,该库将为您提供所需的工具/功能。
http://php.net/manual/en/book.pcntl.php
否则,您需要使用 提到的Quamis 等解决方法:文件标志或锁等。
The only way to handle signals on your PHP script is to re-compile PHP with the PCNTL library that will give you the tools/functions you need.
http://php.net/manual/en/book.pcntl.php
Otherwise, you need to use workarounds like Quamis mentioned : file flags or locks, etc.
如果您知道进程的 ID,您可以
或者如果您不知道进程 ID
来查找 所有您可以发送的可用信号:
如果遇到问题,请将
stderr
重定向到标准输出:这将向您显示终端上出现的任何错误消息(如果您正在执行命令)那样!)。
If you know the process's ID, you could just
Or if you don't know the process ID
To find all the available signals you could send:
If you are having trouble, redirect
stderr
to standard output:This will show you any error messages that would have appeared on the terminal (had you been executing the command that way!).
尝试使用共享内存、锁或文件。如果进程属于不同的用户,则在进程之间发送信号可能不起作用。
例如,如果您需要扩展,使用文件或锁可能会对您有所帮助,因为它比使用信号更容易复制。
正如我所说,信号发送的问题是守护进程必须定期查找事件……通过使用信号,守护进程中的某个触发器将立即被调用,如果您需要快速响应,这会让生活变得更轻松。
Try using shared memory, locks, or files. Sending signals between processes may not work if the process belongs to a different user.
Using files or locks for example may help you if you ever need to scale, as its easier to replicate than using signals.
The problems with signalling like i've said is that the daemon must look periodically for events... by using signals a certain trigger in the daemon would get instantly called, and that makes life easier if you need a fast response back.