本文介绍了将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脚本作为守护进程运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 03:27