centos安装gearmand及php扩展

本文详细介绍了如何使用 yum 命令安装并配置 Gearman 服务,包括下载源码包、编译安装以及编辑 php.ini 文件以启用 Gearman 扩展。同时,提供了客户端与服务端的 PHP 示例代码,演示了如何通过 Gearman 进行任务调度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


#install check
yum -y install yum-fastestmirror
yum -y install patch make gcc gcc-c++ gcc-g77
yum -y install libevent libevent-devel

wget -c http://launchpadlibrarian.net/51244438/gearmand-0.14.tar.gz
tar zxvf gearmand-0.14.tar.gz
cd gearmand-0.14
./configure
make && make install
/sbin/ldconfig
cd ..

#install php extension
wget -c http://pecl.php.net/get/gearman-0.8.0.tgz
tar zxvf gearman-0.8.0.tgz
cd gearman-0.8.0
/opt/modules/php/bin/phpize
./configure --with-php-config=/opt/modules/php/bin/php-config --with-gearman
make
make install
cd ../

#edit php.ini
#extension = gearman.so

#start server
/usr/local/sbin/gearmand -p 4730 -u root -d


#php demo worker.php
<?php
$worker= new GearmanWorker();
$worker->addServer();
$worker->addFunction("title", "title_function");
while ($worker->work());

function title_function($job)
{
return ucwords(strtolower($job->workload()));
}
?>

php worker.php &

#client.php
<?php
$client= new GearmanClient();
$client->addServer();
print $client->do("title", "AlL THE World's a sTagE");
print "\n";
?>

php client.php
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值