1 准备需要的软件
boost 1.43 安装gearmand需要boost 1.37以上版本 下载地址http://sourceforge.net/projects/boost/files/boost/1.43.0/boost_1_43_0.tar.gz/download
icu4c-4_0-src.tgz 安装boost必需 http://downloads.sourceforge.net/project/icu/ICU4C/4.0/icu4c-4_0-src.tgz?use_mirror=cdnetworks-kr-2
gearmand http://launchpad.net/gearmand/trunk/0.23/+download/gearmand-0.23.tar.gz
2 安装gearmand
1)安装boost
wget http://downloads.sourceforge.net/project/icu/ICU4C/4.0/icu4c-4_0-src.tgz?use_mirror=cdnetworks-kr-2
tar zxvf icu4c-4_0-src.tgz
cd icu/source
./configure –prefix=/usr
make
make install
ldconfig
wget http://sourceforge.net/projects/boost/files/boost/1.43.0/boost_1_43_0.tar.gz/download
tar zxvf boost_1_43_0.tar.gz
cd boost_1_43_0
rm -rf /usr/include/boost/
rm -rf /usr/lib/libboost*
./bootstrap.sh
./bjam -sHAVE_ICU=1
编译大概半小时,完成后:
cp ./stage/lib/* /usr/lib
cp -a ./boost /usr/include/
ldconfig
2) 安装gearmand wget http://launchpad.net/gearmand/trunk/0.23/+download/gearmand-0.23.tar.gz
# tar zxvf gearmand-0.23.tar.gz
# cd gearmand-0.23
# ./configure
# make && make install
# ldconfig
3 安装gearmand php扩展
# wget http://pecl.php.net/get/gearman-0.8.0.tgz
# tar zxvf gearman-0.8.0.tgz
# cd gearman-0.8.0
# phpize
# ./configure
# make && make install
接下来在php.ini中找到如下行
extension_dir = "/usr/lib/php/modules"
然后在下面追加
extension="gearman.so"
重启httpd服务 service httpd restart
4 测试gearmand
启动gearman守护进程
gearmand -L 127.0.0.1 -p 4730 -u root -d
创建test_worker.php
<?php$worker= new GearmanWorker();$worker->addServer('127.0.0.1', 4730);$worker->addFunction("reverse", "my_reverse_function");while ($worker->work());function my_reverse_function($job){return strrev($job->workload());}?>
在命令行下执行test_worker.php
php test_worker.php &
这样就添加了名为reverse的worker添加的job server供客户端调用
创建test_client.php
<?php
$client= new GearmanClient();
$client->addServer();
echo $client->do("reverse", "Hello World!");
?>
可以使用命令行和通过web访问
php test_client.php
http://serverip/test_client.php
如果都输出
!dlroW olleH
说明安装配置成功