Installing Gearman for PHP and Ubuntu
Ubuntu Packages
If you’re not on ubuntu then hopefully you can adapt this information for your system, add a comment if you do! For ubuntu I simply needed:
sudo aptitude install gearman-job-server gearman-dev
There should be a running task which is /usr/sbin/gearmand, this listens on port 4730 of localhost by default.
PECL Package
The gearman package in pecl is still in beta (I have no idea why, the documentation seems thin but it does work fine for me), so to install it I had to do:
sudo pecl install gearman-beta
(on Ubuntu 10.10 this worked flawlessly, but there are known issues on earlier versions where make fails due to an old version of libgearman – see the pecl bug for more information)
At this point, everything is set up and I could start using Gearman – I will write more about my experiences as I have them.
Can’t wait to hear how it works out for you. I’ve been thinking of trying gearman myself. It would be great if there was a Windows port. Alas.
You might appreciate this post on integrating gearman into Zend Framework: http://blog.digitalstruct.com/2010/10/17/integrating-gearman-into-zend-framework/
One thing to mention is that you may want to utilize the PPA repositories for gearman if utilizing ubuntu. However, they do not have a maverick one at the moment.
A few things to note about the gearman client in general, if you want to unit test, you will need to create a client for it so that you can wrap the functions since “do” is a keyword :)
A last mention, is that it is a great idea to wrap it just so that you do not have so many different methods and can utilize constants between:
do
doLow
doHigh
Be sure to checkout the the gearman server’s “–job-retries” parameter for poison jobs and a process manager like supervisord to help the PHP workers with their memleaks and fatal errors.
Dean: thanks for the encouragement!
ficusd: That’s a nice link, thanks :) I also referred this really handy post about ZF from CLI, and used that for my workers: http://webfractor.wordpress.com/2008/08/14/using-zend-framework-from-the-command-line/
Mike: thanks for the pointers! I have ended up not unit testing so far, but I will take your advice when I do.
Rob: I got the same advice from weierophinney and I am indeed using supervisord. I haven’t checked any of the gearman settings though, so thanks for mentioning that!
I’ve introduced Gearman into a project I’m working on, and since a few people have asked I thought I’d share my experiences. Basically, this application generates some PDFs from a variety of data sources, makes images, and emails it. Since the whole dat
If anyone is trying to install the pecl php extension and getting error like “can’t read /usr/lib/libuuid.la: No such file or directory
libtool: link: `/usr/lib/libuuid.la’ is not a valid libtool archive” refer to this: http://mgribov.blogspot.com/2010/05/gearman-pecl-package-on-ubuntu-lucid.html
Open /usr/lib/libgearman.la as root, and find a line that says:
dependency_libs=’ -L/usr/lib /usr/lib/libuuid.la’
Replace it with:
dependency_libs=’ -L/usr/lib -luuid’
if dependency_libs=’ -L/usr/lib /usr/lib/libuuid.la’ is not found, simply add
dependency_libs=’ -L/usr/lib -luuid’ to the end of the file
Then
sudo pecl install gearman-beta
should install the extension
Thank you very very much for this post. It was exactly what I was lookign for.
And vrgfa’s hint just saved me a lot of time.
Hah, just had to set this up again, and obviously you’re the top result! Clear, concise… just what I needed! Thanks :-)
Unfortunately – doesn’t seem to be working :(
Did anyone have a problem like this:
configure: error: Please install libgearman
ERROR: `/tmp/pear/temp/gearman/configure' failed
Same error here
checking whether to enable gearman support… yes, shared
not found
configure: error: Please install libgearman
I managed to get this working on Quantal:
1. Add this PPA to your /etc/apt/sources.list:
https://launchpad.net/~gearman-developers/+archive/ppa
2. Install package:
sudo aptitude install gearman-job-server libgearman-dev
3. Install PECL package:
sudo pecl install gearman
4. Add `gearman.so` to you php.ini