Home >Backend Development >PHP Tutorial >Install amqp extension for PHP under Linux linux install php7 php install centos php install
This article introduces the process of installing amqp extension for PHP under Linux. Friends in need can pay attention to it.
Install librabbitmq-c and 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
Install the pecl extension
#下载最新的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
Remember to add the amqp extension to php.ini:
extension=amqp.so
Problems you may encounter during the installation process
1. Lack of libtool package
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
Solution, install libtool, ubuntu:
sudo apt-get install libtool
Other systems are similar
2. If you have other questions, please leave me a message and I will make it up
Use
<?php //配置信息 $conn_args = array( 'host' => '127.0.0.1', 'port' => '5672', 'login' => 'guest', 'password' => 'guest', 'vhost'=>'/' ); //创建连接 $conn = new AMQPConnection($conn_args); if (!$conn->connect()) { die('Not connected <img src="http://www.codeceo.com/wp-content/themes/d-simple/img/smilies/icon_sad.gif" alt="linux 安装php,linux php,php,linux php环境搭建,linux php安装教程,linux安装php环境,linux 安装php7,php安装,centos php安"> ' . 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; } ?>
The above introduces the installation of amqp extension for PHP under Linux, including Linux and PHP installation. I hope it will be helpful to friends who are interested in PHP tutorials.