12

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.

3 Answers 3

19

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.

1
  • 2
    apt-get install supervisor and creating /etc/supervisor/conf.d/gearman.conf with just [program:gearman] and command=/usr/bin/php php_gearman_worker.php was all that was needed for me. Feb 6, 2015 at 0:50
5

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

2
  • Thanks a lot, but I found another more workable way using Supervisord.
    – ObiHill
    Dec 8, 2011 at 16:12
  • GearMan monitor and Gearman Manager together should do the trick. github.com/yugene/Gearman-Monitor
    – rjha94
    Jun 10, 2012 at 10:12
5

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

screen -d -m php worker.php
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.