持续运行的 Gearman Worker
我有一个进程希望能够通过随时启动 Gearman 客户端来在后台运行。
我通过打开到服务器的两个 SSH 连接取得了成功,其中一个连接启动工作程序,另一个连接运行客户端。这会产生所需的输出。
问题是,我希望有一个工作人员在后台不断运行,这样我就可以在需要完成该过程时调用客户端。但是,一旦我关闭正在运行工作程序 PHP 文件的终端,对客户端的调用就不起作用 - 工作程序似乎死了。
有没有办法让工作人员在后台持续运行,这样调用新客户端就可以工作而无需启动新工作人员?
谢谢!
I have a process I'd like to be able to run in the background by starting up a Gearman Client any time.
I've found success by opening up two SSH connections to my server, and in one starting the worker and in the other then running the client. This produces the desired output.
The problem is that, I'd like to have a worker constantly running in the background so I can just call up a client whenever I need to have the process done. But as soon as I close the terminal which has the worker PHP file running, a call to the client does not work - the worker seems to die.
Is there a way to have the worker run constantly in the background, so calling a new client will work without having to start up a new worker?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您希望一个程序即使在其父程序死亡后也能继续运行(即您关闭了终端),则必须使用
nohup
:引用我链接到的相关维基百科页面:
对于另一个(可能更多)有趣的解决方案,请参阅以下文章:将您的 PHP 后台化。
它指向 Supervisord,它确保进程仍在运行,并在必要时重新启动它。
If you want a program to keep running even after its parent is dead (i.e. you've closed your terminal), you must invoke it with
nohup
:Quoting the relevant Wikipedia page I linked to :
For another (possibly more) interesting solution, see the following article : Dæmonize Your PHP.
It points to Supervisord, which makes sures a process is still running, relaunching it if necessary.
主管!
2009 PHP Advent Calendar 有一篇关于使用 Supervisor 的快速文章(和其他技巧)来创建持续运行的 PHP 脚本,而无需处理 PHP 本身的守护进程。
Supervisor!
The 2009 PHP Advent Calendar has a quick article on using Supervisor (and other tricks) to create constantly-running PHP scripts without having to deal with the daemonization process in PHP itself.