在后台运行 Gearman Worker

发布于 2024-12-17 07:50:44 字数 253 浏览 3 评论 0原文

我正在使用 Ubuntu Natty 和 PHP 5.3.8。我刚刚让 Gearman 在我的服务器上工作。

我用 PHP 手册中的一些脚本做了一些测试,一切正常。

但是,我想知道是否有一种方法可以在后台运行工作人员并对其进行监视,以便当我转向多工作人员情况时,我可以跟踪我有多少工作人员在职的。

通常,我必须打开两个终端,一个用于工作人员,一个用于客户。执行 php 脚本后,worker 的状态实际上会“卡住”。

提前致谢。

I'm using Ubuntu Natty with PHP 5.3.8. I just got Gearman working on my server.

I did a few tests with some scripts I got off the PHP Manual, and everything works ok.

However, I'd like to know if there's a way I can run the worker in the background, and also monitor it so that when I move to a multi-worker situation, I can keep track of just how many workers I've got working.

Usually, I would have to open two terminals, one for the worker and one for the client. The one for the worker becomes 'stuck' in effect after the php script is executed.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

千柳 2024-12-24 07:50:44

好的。我找到了解决我之前问题的方法。它涉及使用 Supervisord 来取消齿轮工的工作。

以下是如何安装 Supervisord

apt-get install python-setuptools
easy_install supervisor
echo_supervisord_conf > /etc/supervisord.conf

以下是如何配置它(首先从 此处 获取初始化脚本并将其保存到 < code>/etc/init.d/supervisord),然后执行以下操作:

chmod +x /etc/init.d/supervisord
update-rc.d -f supervisord defaults

然后您需要更新supervisor.conf文件以告诉supervisord您想要作为守护进程运行哪个命令(当然,这将是你的齿轮工工人)。以下只是您要添加到supervisord.conf 文件中的内容的示例,您需要根据自己的具体情况进行更新。

[program:gearman]
command=/usr/bin/php php_gearman_worker.php
numprocs=1
directory=/root/gearman
stdout_logfile=/root/gearman/supervisord.log
environment=GEARMAN_USER=gearman
autostart=true
autorestart=true
user=gearman
stopsignal=KILL

完成后,启动supervisord,即/etc/init.d/supervisord start

执行此操作后,您的 Gearman 工作线程现在处于活动状态,您现在可以通过命令行或使用浏览器运行 gearman 客户端。

我希望这有帮助。

Ok. I found a solution to my earlier problem. It involves using Supervisord to deamonize the gearman worker(s).

Here's how to install Supervisord

apt-get install python-setuptools
easy_install supervisor
echo_supervisord_conf > /etc/supervisord.conf

Here's how to configure it (first get an init script from here and save it to /etc/init.d/supervisord), then do the following:

chmod +x /etc/init.d/supervisord
update-rc.d -f supervisord defaults

You then need to update your supervisor.conf file to tell supervisord which command you want to run as a daemon (of course, this would be your gearman worker). Below is just a sample of what you would add to your supervisord.conf file, you'll need to update it to your own specific situation.

[program:gearman]
command=/usr/bin/php php_gearman_worker.php
numprocs=1
directory=/root/gearman
stdout_logfile=/root/gearman/supervisord.log
environment=GEARMAN_USER=gearman
autostart=true
autorestart=true
user=gearman
stopsignal=KILL

When you're done, then start supervisord i.e. /etc/init.d/supervisord start.

Once you do this, your Gearman worker is now active and you can now run your gearman client via the command line or with your browser.

I hope this helps.

柠檬心 2024-12-24 07:50:44

对于后台工作人员,您可以使用 Brian Moon 的 GearmanManager
https://github.com/brianlmoon/GearmanManager

For background workers you can use GearmanManager by Brian Moon
https://github.com/brianlmoon/GearmanManager

离线来电— 2024-12-24 07:50:44

另一种选择是使用 screen 将工作人员将任务放入独立的 shell 中:

screen -d -m php worker.php

Another option is to use screen to put the worker task into a detached shell:

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