持续运行的 Gearman Worker

发布于 2024-10-29 09:38:13 字数 276 浏览 1 评论 0原文

我有一个进程希望能够通过随时启动 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 技术交流群。

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

发布评论

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

评论(2

薄荷梦 2024-11-05 09:38:13

如果您希望一个程序即使在其父程序死亡后也能继续运行(即您关闭了终端),则必须使用 nohup :

nohup your-command &

引用我链接到的相关维基百科页面:

nohup 是一个要忽略的 POSIX 命令
HUP(挂断)信号,启用
后继续运行的命令
发出该命令的用户已登录
out

HUP(挂断)信号是
按照惯例,终端警告的方式
取决于注销过程。

对于另一个(可能更多)有趣的解决方案,请参阅以下文章:将您的 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 :

nohup your-command &

Quoting the relevant Wikipedia page I linked to :

nohup is a POSIX command to ignore
the HUP (hangup) signal, enabling
the command to keep running after the
user who issues the command has logged
out
.
The HUP (hangup) signal is
by convention the way a terminal warns
depending processes of logout.

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.

摇划花蜜的午后 2024-11-05 09:38:13

有没有办法让工作线程在后台持续运行,这样调用新客户端就可以工作而无需启动新工作线程?

主管

2009 PHP Advent Calendar 有一篇关于使用 Supervisor 的快速文章(和其他技巧)来创建持续运行的 PHP 脚本,而无需处理 PHP 本身的守护进程。

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?

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.

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