• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

RabbitMQ php 施用

php 搞代码 4年前 (2022-01-24) 29次浏览 已收录 0个评论

RabbitMQ php 使用

RabbitMQ是一个开源的基于AMQP(Advanced Message Queuing Protocol)标准,并且可靠性高的企业级消息系统,目前很多网站在用,包括reddit,Poppen.de等。

1. 安装RabbitMQsudo apt-get install rabbitmq-serversudo /etc/init.d/rabbitmq-server start

?

?

?

2. 安装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. 安装php-rabbit扩展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编辑 php.ini 添加:extension=rabbit.so输出phpinfo看下是否扩展已经加载成功,have fun:)

?

?

?

<?php/** * 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 publish($i . 'msg', 'wei.' . $i);    if ($res) {        echo $i . 'msg' . " Yes\n";    } else {        echo $i . 'msg' . " No\n6本文来源gao@dai!ma.com搞$代^码!网7
搞gaodaima代码

"; }} ?>consumer:?View Code PHP<?php/** * consumer demo * * @author wei * @version $Id$ **/$params = array('host' =>'localhost', 'port' => 5672, 'login' => 'guest', 'password' => 'guest', '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";}?>

?

?

?

参考:
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/


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:RabbitMQ php 施用

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址