Wednesday, February 13, 2013

PHP background process with Gearman :how to use

What is Gearman?

Gearman provides a generic application framework to farm out work to other machines or processes that are better suited to do the work. It allows you to do work in parallel, to load balance processing, and to call functions between languages. It can be used in a variety of applications, from high-availability web sites to the transport of database replication events. In other words, it is the nervous system for how distributed processing communicates. A few strong points about Gearman:

Open Source – It’s free! (in both meanings of the word) Gearman has an active open source community that is easy to get involved with if you need help or want to contribute.
Multi-language – There are interfaces for a number of languages, and this list is growing. You also have the option to write heterogeneous applications with clients submitting work in one language and workers performing that work in another.
Flexible – You are not tied to any specific design pattern. You can quickly put together distributed applications using any model you choose, one of those options being Map/Reduce.
Fast – Gearman has a simple protocol and interface with a new optimized server in C to minimize your application overhead.
Embeddable – Since Gearman is fast and lightweight, it is great for applications of all sizes. It is also easy to introduce into existing applications with minimal overhead.
No single point of failure – Gearman can not only help scale systems, but can do it in a fault tolerant way.

For more information read following:
http://php.net/manual/en/book.gearman.php

For installing gearman use following commands.
#yum install gearmand
#yum install php-pecl-gearman

For starting the gearman deamon use following command.
#gearmand -vvvv

For Checking the gearman services use following commands (Gearman Admin Commands.)
#gearadmin –workers
#gearadmin –status

We recommend to Use:
GearmanManager- https://github.com/brianlmoon/GearmanManager

Why use GearmanManager

Running Gearman workers can be a tedious task. Many many files with the same lines of code over and over for creating a worker, connecting to a server, adding functions to the worker, etc. etc. The aim of GearmanManager is to make running workers more of an operational task and less of a development task.

The basic idea is that once deployed, all you need to do is write the code that actually does the work and not all the repetative worker setup. We do this by creating files that contain functions in a specified directory. The file names determine what functions are registered with the gearmand server. This greatly simplifies the function registration.


Source : digcms[dot]com

0 comments:

Post a Comment