RabbitMQ PHP Usage
RABBITMQ is an open source, highly reliable enterprise-class messaging system based on the AMQP (Advanced message Queuing Protocol) standard, with many websites currently in use, including reddit,poppen.de.
1. Installing Rabbitmqsudo apt-get Install Rabbitmq-serversudo/etc/init.d/rabbitmq-server start
?
?
?
2. Installing Librabbitmqsudo apt-get install MERCURIALHG clone HTTP://HG.RABBITMQ.COM/RABBITMQ-CCD Rabbitmq-chg clone http:// Hg.rabbitmq.com/rabbitmq-codegen codegenautoreconf-i &&./configure && make && sudo make Install3. Installing the php-rabbit extension wget http://php-rabbit.googlecode.com/files/php-rabbit.r91.tar.gztar-zxvf PHP-RABBIT.R91.TAR.GZCD Php-rabbit.r91/path/to/php/bin/phpize./configure–with-amqp–with-php-config=/path/to/php/bin/php-configmake && sudo make install edit php.ini add: extension=rabbit.so output phpinfo See if the extension has been loaded successfully, with fun:)
?
?
?
' localhost ', ' port ' = 5672, ' login ' = ' guest ', ' password ' = ' gues ' T ', ' 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 < $i + +) {$res = $exchange->publish ($i. ' msg ', ' Wei '. $i); if ($res) {echo $i. ' Msg '. "Yes\n"; } else {echo $i. ' Msg '. "No\n"; }}? >consumer:? View Code PHP
' localhost ', ' port ' = 5672, ' login ' = ' guest ', ' password ' = ' gues ' T ', ' vhost ' = '/'); $cnn = new Amqpconnect ($params); Create the Queue$queue = new Amqpqueue ($cnn, ' queue1 '); $queueMessages = $queue->consume (100); foreach ($queueMessages as $item) {echo "$i. $item \ n";}? >
?
?
?
Reference:
Http://www.rabbitmq.com/install.html
http://blog.ftofficer.com/2010/03/translation-rabbitmq-python-rabbits-and-warrens/
http://code.google.com/p/php-rabbit/