luyj 发表于 2014-12-23 08:06:25

php gearman集群 安装与运用

做了german集群,所以worker.php要复制两份,当然german都要安装两份。

german是自动根据机器任务程度自动分发的,不需要做任何关于它的配置。

Linux上安装:


202 yum install -y boost-devel gperf libevent-devel libuuid-devel
203wget https://launchpad.net/gearmand/1 ... rmand-1.1.12.tar.gz
204LS
205ls
206tar xf gearmand-1.1.12.tar.gz
207cd gearmand-1.1.12
208ls
209./configure
210make && make install
211/sbin/ldconfig
212cd /opt
213wget http://pecl.php.net/get/gearman-1.1.2.tgz
214tar xf gearman-1.1.2.tgz
215ls
216cd gearman-1.1.2
217ls
218/usr/local/php/bin/phpize
219./configure --with-php-config=/usr/local/php/bin/php-config --with-gearman
220make && make install
221make test
222vi /home/wwwroot/bulutu.a.com/test.php
223vi /usr/local/php/etc/php.ini
224/etc/init.d/php-fpm restart
225/usr/local/sbin/gearman -p 4730 -u root -d
226/usr/local/sbin/gearmand -p 4730 -u root -d
227mkdir -p /usr/local/var/log
228/usr/local/sbin/gearmand -p 4730 -u root -d
229ls /home/wwwroot/bulutu.a.com/
230vi /home/wwwroot/bulutu.a.com/worker.php
231cd /home/wwwroot/bulutu.a.com/
232php worker.php &



worker.php 源码:


$worker = new GearmanWorker();
$worker->addServer("192.168.1.11",4730);
$worker->addServer("192.168.1.12",4730);
$worker->addFunction("title","title_function");
while($worker->work());

//不同机器返回不同以作区别
function title_function($job)
{
return ucwords(strtolower($job->workload()));//192.168.1.11

retrun '12321321';//192.168.1.12

}
?>


client.php 源码:



$client = new GearmanClient();
$makr = 1;
if(!$client->addServer("192.168.1.11",4730)){echo 'hh';exit;}
if(!$client->addServer("192.168.1.12",4730)){echo 'dd';exit;}
print $client->do("title","AIL THE World's a sTagE");
print "";
?>



结果:


页: [1]
查看完整版本: php gearman集群 安装与运用