php 安装rabbitmq拓展_安装 php-rabbit: RabbitMQ 的 PHP 扩展

RabbitMQ 官方提供了三种 PHP 可用的扩展,分别是:

php-amqp

http://code.google.com/p/php-amqp/

php-rabbit

http://code.google.com/p/php-rabbit/

php-amqplib

http://code.google.com/p/php-amqplib/

这里我选择使用 php-rabbit,因为这个项目的 Activity 比较高,名字也比较权威

安装步骤:

下载 RabbitMQ-C 客户端库 librabbitmq:

http://hg.rabbitmq.com/rabbitmq-c/

下载 RabbitMQ 协议代码生成工具:

http://hg.rabbitmq.com/rabbitmq-codegen/

注意 librabbitmq 的版本号,使用最新版本可能会导致下面编译 php-rabbit 时出错:

/bin/sh /work/setup/php-rabbit/libtool –mode=compile cc -I. -I/work/setup/php-rabbit -DPHP_ATOM_INC -I/work/setup/php-rabbit/include -I/work/setup/php-rabbit/main -I/work/setup/php-rabbit -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /work/setup/php-rabbit/rabbit.c -o rabbit.lo

mkdir .libs

cc -I. -I/work/setup/php-rabbit -DPHP_ATOM_INC -I/work/setup/php-rabbit/include -I/work/setup/php-rabbit/main -I/work/setup/php-rabbit -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /work/setup/php-rabbit/rabbit.c -fPIC -DPIC -o .libs/rabbit.o

/work/setup/php-rabbit/rabbit.c: In function ‘zim_rabbit_class___construct’:

/work/setup/php-rabbit/rabbit.c:227: warning: ‘php_std_error_handling’ is deprecated (declared at /usr/local/php/include/php/main/php.h:295)

/work/setup/php-rabbit/rabbit.c:230: warning: ‘php_std_error_handling’ is deprecated (declared at /usr/local/php/include/php/main/php.h:295)

/work/setup/php-rabbit/rabbit.c: In function ‘zim_rabbit_class_isConnected’:

/work/setup/php-rabbit/rabbit.c:329: warning: ‘php_std_error_handling’ is deprecated (declared at /usr/local/php/include/php/main/php.h:295)

/work/setup/php-rabbit/rabbit.c: In function ‘zim_rabbit_queue_class___construct’:

/work/setup/php-rabbit/rabbit.c:363: warning: ‘php_std_error_handling’ is deprecated (declared at /usr/local/php/include/php/main/php.h:295)

/work/setup/php-rabbit/rabbit.c:368: warning: ‘php_std_error_handling’ is deprecated (declared at /usr/local/php/include/php/main/php.h:295)

/work/setup/php-rabbit/rabbit.c: In function ‘zim_rabbit_queue_class_delete’:

/work/setup/php-rabbit/rabbit.c:504: error: unknown field ‘ticket’ specified in initializer

/work/setup/php-rabbit/rabbit.c:512: error: unknown field ‘ticket’ specified in initializer

/work/setup/php-rabbit/rabbit.c: In function ‘zim_rabbit_queue_class_purge’:

/work/setup/php-rabbit/rabbit.c:574: error: unknown field ‘ticket’ specified in initializer

/work/setup/php-rabbit/rabbit.c:580: error: unknown field ‘ticket’ specified in initializer

/work/setup/php-rabbit/rabbit.c: In function ‘zim_rabbit_queue_class_bind’:

/work/setup/php-rabbit/rabbit.c:646: error: unknown field ‘ticket’ specified in initializer

/work/setup/php-rabbit/rabbit.c: In function ‘zim_rabbit_queue_class_unbind’:

/work/setup/php-rabbit/rabbit.c:713: error: unknown field ‘ticket’ specified in initializer

/work/setup/php-rabbit/rabbit.c: In function ‘zim_rabbit_queue_class_consume’:

/work/setup/php-rabbit/rabbit.c:781: error: unknown field ‘ticket’ specified in initializer

/work/setup/php-rabbit/rabbit.c: In function ‘zim_rabbit_queue_class_get’:

/work/setup/php-rabbit/rabbit.c:917: error: unknown field ‘ticket’ specified in initializer

/work/setup/php-rabbit/rabbit.c: In function ‘zim_rabbit_exchange_class___construct’:

/work/setup/php-rabbit/rabbit.c:1169: warning: ‘php_std_error_handling’ is deprecated (declared at /usr/local/php/include/php/main/php.h:295)

/work/setup/php-rabbit/rabbit.c: In function ‘zim_rabbit_exchange_class_delete’:

/work/setup/php-rabbit/rabbit.c:1318: error: unknown field ‘ticket’ specified in initializer

/work/setup/php-rabbit/rabbit.c:1326: error: unknown field ‘ticket’ specified in initializer

/work/setup/php-rabbit/rabbit.c: In function ‘zim_rabbit_exchange_class_bind’:

/work/setup/php-rabbit/rabbit.c:1534: error: unknown field ‘ticket’ specified in initializer

make: *** [rabbit.lo] Error 1

看了下是头文件 /usr/local/include/amqp_framing.h 中的结构体定义与源代码中冲突,因此怀疑是 librabbitmq 版本的问题。

使用 svn 上的代码也不行,很明显当前版本不适用。

看到官方下载页面上的声明:

Specification

The current RabbitMQ server and Java client library releases implement AMQP protocol version 0-8. The .NET/C# client implements AMQP protocol versions 0-8 and 0-9.

估计得用 0.8 版,我使用以下方式安装 librabbitmq 时可以编译通过:

wget http://hg.rabbitmq.com/rabbitmq-c/archive/ce1eaceaee94.tar.gz -O rabbitmq-c.tar.gz

tar zxf rabbitmq-c.tar.gz

wget http://hg.rabbitmq.com/rabbitmq-codegen/archive/c7c5876a05bb.tar.gz -O rabbitmq-codegen.tar.gz

tar zxf rabbitmq-codegen.tar.gz

mv rabbitmq-codegen-c7c5876a05bb/ rabbitmq-c-ce1eaceaee94/codegen

cd rabbitmq-c-ce1eaceaee94/

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

如果提示:

checking finding a python with simplejson installed… configure: error: could not find a python that can ‘import simplejson’

请安装 python 的 simplejson 库:

# wget http://pypi.python.org/packages/source/s/simplejson/simplejson-2.1.1.tar.gz

# tar zxf simplejson-2.1.1.tar.gz

# cd simplejson-2.1.1

# python setup.py install

下载并安装 php-rabbit:

# wget http://php-rabbit.googlecode.com/files/php-rabbit.r91.tar.gz

# tar zxf php-rabbit.r91.tar.gz

# cd php-rabbit

# /usr/local/php/bin/phpize

# ./configure –with-php-config=/usr/local/php/bin/php-config –with-rabbit

# make && make install

修改 php.ini,在尾部加上:

extension = rabbit.so

查看扩展是否安装成功:

# php -m | grep rabbit

rabbit

完工!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值