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
完工!!
作者:Hily 原始链接:http://hily.me/blog/2010/05/php-rabbit-installation/
>> 本文固定链接: http://www.vcgood.com/archives/3432
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 比较高,名字也比较权威 http://hily.me/blog/wp-includes/images/smilies/icon_smile.gif','Image‘);” onmouseover=”this.style.cursor=’hand’” onmouseout=”this.style.cursor=”” src=”http://hily.me/blog/wp-includes/images/smilies/icon_smile.gif” border=”0″ alt=”:)” title=”:)” />
安装步骤:
下载 RabbitMQ-C 客户端库 librabbitmq:
http://hg.rabbitmq.com/rabbitmq-c/
下载 RabbitMQ 协议代码生成工具:
http://hg.rabbitmq.com/rabbitmq-codegen/
注意 librabbitmq 的版本号,使用最新版本可能会导致下面编译 php-rabbit 时出错:
看了下是头文件 /usr/local/include/amqp_framing.h 中的结构体定义与源代码中冲突,因此怀疑是 librabbitmq 版本的问题。
使用 svn 上的代码也不行,很明显当前版本不适用。
看到官方下载页面上的声明:
估计得用 0.8 版,我使用以下方式安装 librabbitmq 时可以编译通过:
如果提示:
请安装 python 的 simplejson 库:
下载并安装 php-rabbit:
修改 php.ini,在尾部加上:
extension = rabbit.so
查看扩展是否安装成功:
# php -m | grep rabbit
rabbit
完工!!
作者:Hily 原始链接:http://hily.me/blog/2010/05/php-rabbit-installation/