Install gearman centos from pecl

how to install gearman

1. Install php-devel dependency , gearmand , libgearman-devel via yum
# yum install php-devel
# yum install -y gearmand libgearman-devel
# pecl install gearman

2. Get the latest stable build from Gearman PECL extension page. The current stable release is version 1.1.1
# wget
# tar -xzvf gearman-1.1.1.tgz
# cd gearman-1.1.1
3. Now phpize and complie it:
# phpize
# make
# make install

you can see the file at /usr/lib64/php/modules/

next step, create file gearman.ini at /etc/php.d/ and write below line in this file

restart webserver and check your phpinfo

how to run gearmand as background (type on ssh)

nohup gearmand > /dev/null 2>&1 &


gearmand -d -u root

you must to specify hostname and port !!!!!!!!!!!!!!!! look like this

$gmworker=new GearmanWorker();
$gmworker->addFunction("JobName", "JobFunction");

how to handle gearman client script connection status to connect gearman worker

$gmclient=new GearmanClient();
$gmclient->doBackground('JobName', $json_params);
# Check for various return packets and errors.
switch ($gmclient->returnCode()) {
list($numerator, $denominator) = $gmclient->doStatus();
echo "Status: $numerator/$denominator complete";
echo "Failed";
case GEARMAN_SUCCESS:// It's perfect work
echo "Job process successfully";
default://such as can't connect gearman server
echo "RET: " . $gmclient->returnCode() . "";

how to run gearman worker script as background on centos

nohup php worker.php > /dev/null 2>&1 &

what does “/dev/null 2>&1 &” mean?

> is for redirect

/dev/null is a black hole where any data sent, will be discarded

2 is the file descriptor for Standard Error

> is for redirect

& is the symbol for file descriptor (without it, the following 1 would be considered a filename)

1 is the file descriptor for Standard Out

& the last one that mean run service as background

Therefore >/dev/null 2>&1 & is redirect the output of your program to /dev/null. Include both the Standard Error and Standard Out and run as background.

gearman monitor by gearman ui

how to remove gearman worker function (if you not used)

gearadmin --drop-function XXX

how to test client (command line) This creates a background job (-b option) for the function testq (-f testq option) with the payload being the string “payload”

gearman -h localhost -p 4730 -f testq -b payload

#Don’t forget to rerun gearman worker script if you change this file

This entry was posted in queue. Bookmark the permalink.