Use PHP + RabbitMQ in Ubuntu

Source: Internet
Author: User
Tags rabbitmq
RabbitMQ is an open-source enterprise-level message system based on AMQP (AdvancedMessageQueuingProtocol) and has high reliability. It is currently used by many websites, including reddit and Poppen.de. 1. Install RabbitMQsudoapt-getinstallrabbitmq-serversudo/etc/init. d/rabbitmq-serverstart in Ubuntu

RabbitMQ is an open-source enterprise-level Message system based on AMQP (Advanced Message Queuing Protocol) and has high reliability. It is currently used by many websites, including reddit and Poppen.de.

1. Install RabbitMQ in Ubuntu
Sudo apt-get install rabbitmq-server
Sudo/etc/init. d/rabbitmq-server start

2. Install librabbitmq
Sudo apt-get install mercurial
Hg clone http://hg.rabbitmq.com/rabbitmq-c
Cd rabbitmq-c
Hg clone http://hg.rabbitmq.com/rabbitmq-codegen codegen
Autoreconf-I &./configure & make & sudo make install

3. install php-rabbit Extension
Wget http://php-rabbit.googlecode.com/files/php-rabbit.r91.tar.gz
Tar-zxvf php-rabbit.r91.tar.gz
Cd php-rabbit.r91
/Path/to/php/bin/phpize
./Configure-with-amqp-with-php-config =/path/to/php/bin/php-config
Make & sudo make install
Edit php. ini to add:
Extension = rabbit. so
Output phpinfo to check whether the extension has been loaded successfully. have fun :)

4. Demo program
Producer:

   /** * producer demo * * @author wei * @version $Id$ **/$params = array('host' =>'localhost',                'port' => 5672,                'login' => 'guest',                'password' => 'guest',                'vhost' => '/');$cnn = new AMQPConnect($params); // declare Exchange$exchange = new AMQPExchange($cnn);$exchange->declare('ex1', 'topic', AMQP_DURABLE ); // declare Queue$queue = new AMQPQueue($cnn);  $queue->declare('queue1', AMQP_DURABLE);  // bind Queue$queue->bind('ex1','wei.#'); // publishing$msg = "msg"; for ($i=0; $i < 100; $i++) { $res = $exchange->publish($i . 'msg', 'wei.' . $i);if ($res) {echo $i . 'msg' . " Yes\n";} else {echo $i . 'msg' . " No\n";}} ?>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.