在后台运行Gearman工人 [英] Running Gearman Workers in the Background

查看:84
本文介绍了在后台运行Gearman工人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Ubuntu Natty与PHP 5.3.8一起使用.我刚让Gearman在服务器上工作.

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

我使用PHP手册对一些脚本进行了一些测试,一切正常.

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.

通常,我将不得不打开两个终端,一个用于工作人员,一个用于客户端.在执行php脚本后,供工作人员使用的一个卡住了.

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.

谢谢.

推荐答案

好.我找到了解决我以前的问题的方法.它涉及使用Supervisord来妖the齿轮工.

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

这是安装Supervisord的方法

Here's how to install Supervisord

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

这里是配置它的方法(首先从此处获取一个初始化脚本并将其保存到/etc/init.d/supervisord ),然后执行以下操作:

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

然后,您需要更新您的supervisor.conf文件,以告诉supervisor您想作为守护程序运行哪个命令(当然,这将是您的齿轮工).以下只是添加到supervisord.conf文件中的示例,您需要将其更新为自己的特定情况.

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

完成后,请启动受监控的用户,即/etc/init.d/supervisord start.

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

执行此操作后,您的Gearman工作人员现在处于活动状态,现在可以通过命令行或浏览器运行Gearman客户端.

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.

我希望这会有所帮助.

这篇关于在后台运行Gearman工人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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