将 php 脚本作为守护进程运行 [英] Run php script as daemon process

查看:41
本文介绍了将 php 脚本作为守护进程运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要运行一个 php 脚本作为守护进程(等待指令并做一些事情).cron 作业不会为我做这件事,因为一旦指令到达就需要采取行动.我知道由于内存管理问题,PHP 并不是守护进程的最佳选择,但由于各种原因,我必须在这种情况下使用 PHP.我遇到了 libslack 的一个名为 Daemon(http://libslack.org/daemon)的工具,它似乎对我有帮助管理守护进程,但在过去 5 年中没有任何更新,所以我想知道您是否知道其他一些适合我的情况的替代方案.任何信息将不胜感激.

I need to run a php script as daemon process (wait for instructions and do stuff). cron job will not do it for me because actions need to be taken as soon as instruction arrives. I know PHP is not really the best option for daemon processes due to memory management issues, but due to various reasons I have to use PHP in this case. I came across a tool by libslack called Daemon (http://libslack.org/daemon) it seems to help me manage daemon processes, but there hasn't been any updates in the last 5 years, so I wonder if you know some other alternatives suitable for my case. Any information will be really appreciated.

推荐答案

您可以使用

nohup php myscript.php &

& 将您的进程置于后台.

the & puts your process in the background.


是的,有一些缺点,但无法控制?那是错误的.
一个简单的 kill processid 将停止它.它仍然是最好和最简单的解决方案.


Yes, there are some drawbacks, but not possible to control? That's just wrong.
A simple kill processid will stop it. And it's still the best and simplest solution.

这篇关于将 php 脚本作为守护进程运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆