本篇内容主要讲解“怎样在Linux下给PHP安装amqp扩展”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎样在Linux下给PHP安装amqp扩展”吧!
怎样在Linux下给PHP安装amqp扩展
安装librabbitmq-c和rabbitmq-codegen
#下载0-9-1版的rabbitmq-c
gitclonegit://github.com/alanxz/rabbitmq-c.git
cdrabbitmq-c
#Enableandupdatethecodegengitsubmodule
gitsubmoduleinit
gitsubmoduleupdate
#Configure,compileandinstall
autoreconf-i&&./configure&&make&&sudomakeinstall
安装pecl扩展
#下载最新的amqp扩展
wgethttp://pecl.php.net/get/amqp-1.0.9.tgz
tarxvzfamqp-1.0.9.tgz
cdamqp-1.0.9&&phpize
./configure--with-amqp&&make&&sudomakeinstall
记得在php.ini中加入amqp扩展:
extension=amqp.so
安装amqp扩展会遇到哪些问题
1、缺少libtool包
configure.ac:installing./install-sh
configure.ac:installing./missing
configure.ac:34:installing./config.guess
configure.ac:34:installing./config.sub
Makefile.am:3:LibtoollibraryusedbutLIBTOOLisundefined
Makefile.am:3:
Makefile.am:3:TheusualwaytodefineLIBTOOListoaddAC_PROG_LIBTOOL
Makefile.am:3:toconfigure.acandrunaclocalandautoconfagain.
Makefile.am:CobjectsinsubdirbutAM_PROG_CC_C_Onotinconfigure.ac
Makefile.am:installing./compile
Makefile.am:installing./depcomp
autoreconf:automakefailedwithexitstatus:1
解决办法,安装libtool,ubuntu:
sudoapt-getinstalllibtool
其他系统类似
使用
//配置信息
$conn_args=array(
'host'=>'127.0.0.1',
'port'=>'5672',
'login'=>'guest',
'password'=>'guest',
'vhost'=>'/'
);
//创建连接
$conn=newAMQPConnection($conn_args);
if(!$conn->connect()){
die('Notconnected:('.PHP_EOL);
}
//OpenChannel
$channel=newAMQPChannel($conn);
//Declareexchange
$exchange=newAMQPExchange($channel);
$exchange->setName('extest');
$exchange->setType('fanout');
$exchange->declare();
//CreateQueue
$queue=newAMQPQueue($channel);
$queue->setName('qutest');
$queue->declare();
//Binditontheexchangetorouting.key
$exchange->bind('qutest','routing.key');
$data=array(
'Name'=>'foobar',
'Args'=>array("0","1","2","3"),
);
//生产者,向RabbitMQ发送消息
$message=$exchange->publish(json_encode($data),'key');
if(!$message){
echo'Messagenotsent',PHP_EOL;
}else{
echo'Messagesent!',PHP_EOL;
}
//消费者
while($envelope=$queue->get(AMQP_AUTOACK)){
echo($envelope->isRedelivery())'Redelivery':'NewMessage';
echoPHP_EOL;
echo$envelope->getBody(),PHP_EOL;
}
>
到此,相信大家对“怎样在Linux下给PHP安装amqp扩展”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。