您好,登錄后才能下訂單哦!
本篇內容主要講解“怎樣在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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。