Gearman是一個用來把工做委派給其餘機器、分佈式的調用更適合作某項工做的機器、併發的作某項工做在多個調用間作負載均衡php
準備軟件包linux
gearmand-1.1.12.tar.gz併發
gearman-1.1.1.tgz php擴展負載均衡
安裝支持組件分佈式
yum -y install boost-devel* gperf* libevent-devel* libuuid-devel*ui
./configurespa
make命令行
make installdebug
ldconfigrest
安裝gearman
tar xf gearmand-1.1.12.tar.gz
cd gearmand-1.1.12
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
安裝php擴展
tar xf gearman-1.1.1.tgz
cd gearman-1.1.1
/usr/local/php/bin/phpize --with-php-config=/usr/local/php/bin/php-config
./configure --with-php-config=/usr/local/php/bin/php-config
make
配置gearman
cp /tools/gearman-1.1.1/modules/gearman.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226
vi /usr/local/php/etc/php.ini
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226" extension="gearman.so"
service httpd restart
開始使用
mkdir -p /usr/local/var/log/
echo '' > /usr/local/var/log/gearmand.log
gearmand -d
ps -ef | grep gearman
root 15045 1 0 21:50 ? 00:00:00 gearmand -d root 15053 1 0 21:51 ? 00:00:00 gearmand -d root 15056 112065 0 21:52 pts/3 00:00:00 grep gearman
/usr/local/php/bin/php -c /usr/local/php/etc/php.ini client.php
/usr/local/php/bin/php -c /usr/local/php/etc/php.ini worker.php
附: 幾個代碼示例
把代碼放到htdocs目錄下, 分別訪問 worker.php 和 client.php
在linux命令行下執行也能夠...
;