linux下给php安装amqp扩展-亚博电竞手机版
linux
2020年03月29日 23:49
1
本文介绍了在linux下给php安装amqp扩展的过程,有需要的朋友可以关注一下。
安装librabbitmq-c和rabbitmq-codegen
# 下载0-9-1版的rabbitmq-c git clone git://github.com/alanxz/rabbitmq-c.git cd rabbitmq-c # enable and update the codegen git submodule git submodule init git submodule update # configure, compile and install autoreconf -i && ./configure && make && sudo make install
安装pecl扩展
#下载最新的amqp扩展 wget http://pecl.php.net/get/amqp-1.0.9.tgz tar xvzf amqp-1.0.9.tgz cd amqp-1.0.9 && phpize ./configure --with-amqp && make && sudo make install
记得在php.ini中加入amqp扩展:
extension=amqp.so
安装过程中可能会遇到的问题
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: libtool library used but libtool is undefined makefile.am:3: makefile.am:3: the usual way to define libtool is to add ac_prog_libtool makefile.am:3: to configure.ac and run aclocal and autoconf again. makefile.am: c objects in subdir but am_prog_cc_c_o not in configure.ac makefile.am: installing ./compile makefile.am: installing ./depcomp autoreconf: automake failed with exit status: 1
解决办法,安装libtool,ubuntu:
sudo apt-get install libtool
其他系统类似
2、如果还有其他问题,欢迎给我留言,我补上
使用
'127.0.0.1', 'port' => '5672', 'login' => 'guest', 'password' => 'guest', 'vhost'=>'/' ); //创建连接 $conn = new amqpconnection($conn_args); if (!$conn->connect()) { die('not connected' . php_eol); } // open channel $channel = new amqpchannel($conn); // declare exchange $exchange = new amqpexchange($channel); $exchange->setname('extest'); $exchange->settype('fanout'); $exchange->declare(); // create queue $queue = new amqpqueue($channel); $queue->setname('qutest'); $queue->declare(); // bind it on the exchange to routing.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 'message not sent', php_eol; } else { echo 'message sent!', php_eol; } //消费者 while ($envelope = $queue->get(amqp_autoack)) { echo ($envelope->isredelivery()) ? 'redelivery' : 'new message'; echo php_eol; echo $envelope->getbody(), php_eol; } ?>
展开全文