One of the reasons I love working at Leevio is the tons of new stuff I learn from here. The latest one is – Gearman!
Gearman is an application framework for distributing workload. How does it work? Simple, you run the core daemon (gearmand) with necessary configurations (ip, port, mode, data storage etc) and a worker process registers itself with a named hook. Then, when you need to run that worker, just make a call from the client side.In plain English, the process may read like this:
1) Gearman is the project manager in your office.
2) A new worker joins your office and tells the project manager that he can build awesome wordpress themes.
3) The project manager takes note on his capabilities and waits for clients.
4) A client calls and orders a wordpress theme with specifications.
5) The project manager then passes the specifications to the new wordpress developer, gets the work done by him and returns the result to the client.
The task can be run both in foreground and background. Gearman is multi-threaded, asynchronous, fault tolerant and has multiple language support. So what does this all translate into?
— Run necessary “jobs” in the background
— Write codes in multiple languages
— Build multi-threaded and asynchronous task handlers
— Build task queues instead of draining out all the system resources with concurrent processes
Gearman has PHP support. That means PHP web apps can take the advantage of gearman to offload their “jobs” to the gearman server for background processing.
Who uses Gearman with PHP?
— Yahoo (6M jobs per day)
— Digg (400k jobs per day)
— Xing.com and many others
How do we get started with Gearman? Well, the web is so full of Gearman topics that I am not going to write the codes myself. I would rather point you to articles written by more skilled people than me:
— Rasmus Lerdorf (Father of PHP): http://toys.lerdorf.com/archives/51-Playing-with-Gearman.html
— Matthew Weier O’Phinney (Developer of ZF): http://weierophinney.net/matthew/archives/240-Writing-Gearman-Workers-in-PHP.html
— Cesar D. Rodas on PHPClasses: http://www.phpclasses.org/blog/post/108-Distributing-PHP-processing-with-Gearman.html
— IBM Developer Works: http://www.ibm.com/developerworks/opensource/library/os-php-gearman/
— Gonzalo Ayuso: http://gonzalo123.wordpress.com/2011/03/07/watermarks-in-our-images-with-php-and-gearman/
Installation Notes:
— http://blog.stuartherbert.com/php/2010/02/26/getting-gearman-up-and-running-on-ubuntu-karmic/
Gearman Tricks:
— http://till.klampaeckel.de/blog/archives/94-start-stop-daemon,-Gearman-and-a-little-PHP.html