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 http://pecl.php.net/get/gearman-1.1.1.tgz
# tar -xzvf gearman-1.1.1.tgz
# cd gearman-1.1.1
3. Now phpize and complie it:
# phpize
#./configure
# make
# make install

you can see the file gearman.so at /usr/lib64/php/modules/

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

extension=gearman.so

restart webserver and check your phpinfo

how to run gearmand as background (type on ssh)

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

or

gearmand -d -u root

you must to specify hostname and port !!!!!!!!!!!!!!!! look like this
http://stackoverflow.com/questions/29414652/gearman-stop-start-restart-command

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

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

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

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
http://gaspaio.github.io/gearmanui/

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.