日期:2014-05-17  浏览次数:20374 次

给PHP安装amqp扩展

有史以来最坑爹的一次扩展安装,不晓得诸位有没有尝试过…………各种报错啊!有木有?!¥#@%%&*……

捣鼓半天,只编译了个0.1.x的扩展版本,瞅了下,擦,函数少的可怜啊- -||| 

不行,继续~

经过一天的努力,老天总算开眼了,赶紧总结下吧~

----------------------------------------------- 我是分割线 ---------------------------------------------------

AMQP——高级消息队列协议,目前比较有名气的实现大概就是大名鼎鼎的RabbitMQ了。

(不了解的童鞋先看下我这篇转载吧:《[RabbitMQ+Python入门经典] 兔子和兔子窝》)

PHP扩展当然还是官方推荐的好了。OK,就它了 http://php.net/manual/en/book.amqp.php 

To install the AMQP PHP extension, you must first install the ? librabbitmq library. You will need the 0-9-1 version of the rabbitmq-c client library, linked to the rabbitmq-codegen version that corresponds to the version of the broker you are using. Use the following steps to download and install the library:


  # Download the rabbitmq-c library @ version 0-9-1

  hg clone http://hg.rabbitmq.com/rabbitmq-c/rev/b01825ecc112 rabbitmq-c

  cd rabbitmq-c

  # Add the codegen requirement. To find the full list, go here: http://hg.rabbitmq.com/rabbitmq-codegen/tags

  # and copy the URL for the appropriate broker version.

  hg clone http://hg.rabbitmq.com/rabbitmq-codegen/rev/16bbcb711380 codegen

  # Configure, compile and install

  autoreconf -i && ./configure && make && sudo make install

扩展是C写的,由于C与RabbitMQ通信一般需要依赖rabbitmq-c库(也就是librabbitmq),所以编译扩展前需要先装依赖库。好吧,那就按要求装吧~

原文是用hg工具,需要装mercurial(一个轻量级的版本控制系统),这里就不介绍了,我们还是用传统的方法。

首先,到这里下载rabbitmq-c的v0.2版:https://github.com/alanxz/rabbitmq-c/tags OR 直接shell:

wget https://github.com/alanxz/rabbitmq-c/tarball/0.2

tar zxvf 0.2

cd alanxz-rabbitmq*

(为什么0.2版?好吧,我也不知道,总之它的各版本兼容性非常不好,经过我屡试屡败屡败试……发现0.2版还算顺利 - -)

接着,到这里下载最新版的codegen配件:https://github.com/rabbitmq/rabbitmq-codegen/downloads ,OR 直接shell:

wget https://github.com/rabbitmq/rabbitmq-codegen/tarball/master

tar zxvf master 

mv rabbitmq-* codegen

(上面这步必须要把其解压,并放到rabbitmq-c的目录中的codegen目录中,也就是上面最后那步做的。)

按照手册介绍,先进行:

autoreconf -i

如果你一切顺利,没有报错,那么恭喜了!后面则是常规操作:

./configure && make && make install

如果仍未报错,哇塞,我只能说你NB!可以直接进行扩展编译了。

不过大部分情况下你或许和我一样遇到各种各样报错信息,那么后面我们再说,这里先把编译扩展顺带说完。

直接回到官方下载(我下载的是1.0.0版,新的版本我没事试,应该也可以的) http://pecl.php.net/package/amqp ,并编译成so文件 OR shell:

wget http://pecl.php.net/get/amqp-1.0.0.tgz

tar zxvf amqp-1.0.0.tgz

cd amqp-1.0.0

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/p