本次测试环境

系统:CentOS5.8 x86-64

PHP:5.2.16(源码编译安装的)

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

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

在网上找了很多方法,最后没有一个很详细的,此处将主要步骤做了一次细化,大部分原因是缺少相关的安装包

1.配置yum的安装地址

[root

@cc amqp]# wget -O /etc/yum.repos.d/epel-erlang.repo http://repos.fedorapeople.org/repos/peter/erlang/epel-erlang.repo

[root

@cc amqp]# rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc

2.安装librabbitmq,建议通过yum的方式的安装,否则后面将会非常的痛苦

[root

@cc amqp]# yum install librabbitmq

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

https://github.com/alanxz/rabbitmq-c/tags

或者直接shell:(注意:此处要求你的系统已经安装了openssl,否则就会下载失败,如果没有安装 yum install openssl)

[root

@cc amqp]# wget https://github.com/alanxz/rabbitmq-c/tarball/0.2

[root

@cc amqp]# tar zxvf 0.2

[root

@cc amqp]# mv alanxz-rabbitmq-c-* rabbitmq-c

[root

@cc amqp]# cd rabbitmq-c

4.到这里下载最新版的codegen配件:

https://github.com/rabbitmq/rabbitmq-codegen/downloads

或者直接shell:(注意现在所在目录,下载的文件或者压缩包必须放到rabbitmq-c的目录中的codegen目录中)

[root

@cc rabbitmq-c]# wget https://github.com/rabbitmq/rabbitmq-codegen/tarball/master

[root

@cc rabbitmq-c]# tar zxvf master

[root

@cc rabbitmq-c]# mv rabbitmq-rabbitmq-codegen-* codegen

5.按照手册介绍进行:

[root

@cc rabbitmq-c]# autoreconf -i

[root

@cc rabbitmq-c]# ./configure && make && make install

如果此步没有报错,恭喜你,基本成功了,不过大部分情况下你或许和我一样遇到各种各样报错信息,参考最后的错误,这里先把编译扩展顺带说完。

6.直接回到官方下载(我下载的是1.0.9版,此处用的是截止发blog时的最新版本)

http://pecl.php.net/package/amqp

或者shell:(注意:此时的目录不再是rabbitmq-c了)

[root

@cc amqp]# wget http://pecl.php.net/get/amqp-1.0.9.tgz

[root

@cc amqp]# tar zxvf amqp-1.0.9.tgz

[root

@cc amqp]# cd amqp-1.0.9

[root

@cc amqp-1.0.9]# /opt/webserver/php/bin/phpize

[root

@cc amqp-1.0.9]# ./configure --with-php-config=/opt/webserver/php/bin/php-config --with-amqp

[root

@cc amqp-1.0.9]# make && make install

[root

@cc amqp-1.0.9]# vim /opt/webserver/php/etc/php.ini

将amqp.so 加入到 extension_dir下一行,结果如下

extension_dir = "/opt/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"

extension = "amqp.so"

演示代码

登录名、密码是在服务端添加好的

代码参考官方进行修改

$channelName="myisccchange";

$channelType="fanout";

$queueName="myisccqueue";

$key="myiscckey";

$text = "我是陈聪,测试一下中文";

$connection = new AMQPConnection();

$connection->setLogin("cc");

$connection->setPassword("123456");

$connection->setVhost("/cc");

$connection->connect();

if (!$connection->isConnected()) {

die('Not connected :(' . PHP_EOL);

}

// Open Channel

$channel = new AMQPChannel($connection);

// Declare exchange

$exchange = new AMQPExchange($channel);

$exchange->setName($channelName);

$exchange->setType($channelType);

$exchange->declare();

// Create Queue

$queue = new AMQPQueue($channel);

$queue->setName($queueName);

$queue->declare();

$message = $exchange->publish($text.time(), $key);

if (!$message) {

echo 'Message not sent', PHP_EOL;

} else {

echo 'Message sent!', PHP_EOL;

}

?>

$channelName="myisccchange";

$channelType="fanout";

$queueName="myisccqueue";

$key="myiscckey";

$connection = new AMQPConnection();

$connection->setLogin("cc");

$connection->setPassword("123456");

$connection->setVhost("/cc");

$connection->connect();

if (!$connection->isConnected()) {

die('Not connected :('. PHP_EOL);

}

// Open channel

$channel = new AMQPChannel($connection);

// Open Queue and bind to exchange

$queue = new AMQPQueue($channel);

$queue->setName($queueName);

$queue->bind($channelName, $key);

$queue->declare();

// Prevent message redelivery with AMQP_AUTOACK param

while(true){

while ($envelope = $queue->get(AMQP_AUTOACK)) {

echo ($envelope->isRedelivery()) ? 'Redelivery' : 'New Message';

echo PHP_EOL;

echo $envelope->getBody(), PHP_EOL;

}

sleep(5);

}

?>

安装过程中的错误

好了,如果你和我一样悲催,从autoreconf -i 就开始玩命报错,那么我这里提供一些可能有用的处理方法(部分是实际遇到的,部分是从网上查找的)

1.autoreconf 时有可能遇到如下报错:

场景一:

错误描述:onfigure.ac:60: error: possibly undefined macro: AS_CASE

If this token and others are legitimate, please use m4_pattern_allow.

See the Autoconf documentation.

configure.ac:69: error: possibly undefined macro: AS_IF

configure.ac:92: error: possibly undefined macro: AC_PATH_PROGS_FEATURE_CHECK

configure.ac:97: error: possibly undefined macro: AC_MSG_RESULT

configure:2907: error: possibly undefined macro: m4_foreach_w

autoreconf: /usr/bin/autoconf failed with exit status: 1

解决办法:奇怪的是,当我再次执行却报不同的错,网上有人也是这样....

场景二:

错误描述:configure.ac: installing `./install-sh'

configure.ac: installing `./missing'

configure.ac:34: installing `./config.guess'

configure.ac:34: installing `./config.sub'

Makefile.am:3: Libtool library used but `LIBTOOL' is undefined

Makefile.am:3:

Makefile.am:3: The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'

Makefile.am:3: to `configure.ac' and run `aclocal' and `autoconf' again.

Makefile.am: C objects in subdir but `AM_PROG_CC_C_O' not in `configure.ac'

Makefile.am: installing `./compile'

Makefile.am: installing `./depcomp'

autoreconf: automake failed with exit status: 1

解决办法:首先确保一些必要的依赖库是否已安装,如:libtool、autoconf、automake 等

这个大家自行google下载并编译安装,常规操作,没啥说的,这里我直接yum了:

yum install libtool autoconf automake

看下libtoolize在哪:

whereis libtoolize

显示例如:libtoolize: /usr/bin/libtoolize,则可执行一下

/usr/bin/libtoolize

还有可能会出现这种错:

/usr/share/aclocal/libmcrypt.m4:17: warning: underquoted definition of AM_PATH_LIBMCRYPT

/usr/share/aclocal/libmcrypt.m4:17:   run info '(automake)Extending aclocal'

/usr/share/aclocal/libmcrypt.m4:17:   or see http://sources.redhat.com/automake/automake.html#Extending-aclocal

解决办法如下:

编辑:/usr/share/aclocal/libmcrypt.m4

修改17行的:AC_DEFUN(AM_PATH_LIBMCRYPT,   为  AC_DEFUN([AM_PATH_LIBMCRYPT],

场景三:

错误描述:/usr/bin/libtoolize 时可能会报的错:

libtoolize: putting auxiliary files in `.'.

libtoolize: linking file `./ltmain.sh'

libtoolize: Consider adding `AC_CONFIG_MACRO_DIR([m4])' to configure.ac and

libtoolize: rerunning libtoolize, to keep the correct libtool macros in-tree.

libtoolize: Consider adding `-I m4' to ACLOCAL_AMFLAGS in Makefile.am.

解决办法:报错很明确,按照提示操作即可:

编辑:configure.ac

添加一行:AC_CONFIG_MACRO_DIR([m4])

重新执行:/usr/bin/libtoolize

编辑:Makefile.am

添加一行:ACLOCAL_AMFLAGS=-I m4

场景四:

错误描述:./configure 时可能会报的错:

checking location of AMQP codegen directory... configure: error: could not find AMQP spec file at "'/codegen/amqp-0.9.1.json'"

解决办法:configure文件中目录与实际情况不符,虽然可以通过手动修改解决,但不建议,其实应该是rabbitmq-c和codegen的版本不匹配造成的,更换版本。

场景五:

错误内容:configure: error: could not find a python that can 'import simplejson'

解决办法:请安装 python 的 simplejson 库:

(因为simplejson是最新版本,所以python的版本要在2.5以上,或者下载一个低版本的simplejson,例如python2.4对应的版本

simplejson-

2.0.0就可以用,如果没有安装python或者版本不够 yum install python)

[root

@cc amqp]# wget http://pypi.python.org/packages/source/s/simplejson/simplejson-3.0.7.tar.gz

[root

@cc amqp]# tar zxf simplejson-3.0.7.tar.gz

[root

@cc amqp]# cd simplejson-3.0.7

[root

@cc amqp]# python setup.py install

php amqp扩展安装,Linux下PHP扩展amqp安装相关推荐

  1. mysql5.7.20linux安装,linux下 mysql5.7.20安装(精华)

    在linux 系统中mysql配置文件的读取顺序为: /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf 第一步 创 ...

  2. linux eclipse插件安装,Linux 下 EclipseME 插件的安装步骤

    Linux 下 EclipseME 插件的安装步骤 最近在linux下作开发,参考网络资料,成功将 eclipseME 插件安装至 eclipse.这里记录下来,只为了方便更多的人! 背景: linu ...

  3. linux medea 软件安装,linux下超详细教程安装phonopy

    参考资料: (1)        http://blog.csdn.net/txcokokok/article/details/42178889 (2)        http://blog.sina ...

  4. php redis 扩展 编译安装,Linux 下 PHP 扩展 redis 编译安装

    Linux环境为 CentOS6.5 64位 安装redis 比较简单,也没什么说的,看官网就行,链接:http://redis.io/download 主要看底部的东西. 安装好 redis 好之后 ...

  5. linux php imagick 扩展安装,linux下为php5.3安装Imagick扩展

    imagick是一个PHP的扩展,它调用ImageMagick提供的API来进行图片的操作 ImageMagick是一套软件系列,主要用于图片的创建.编辑以及转换等,详细的解释见ImageMagick ...

  6. linux裸机网络安装,linux下PXEServer实现网络安装【实验】

    实验报告 实验一 实验名称:搭建PXEServer实现网络安装 步骤1:基本环境 整个实验来说,我们远程装系统需要用到网络那么就得分配iP,需要dhcp服务器,同时就得传输相关开机引导文件就需要tft ...

  7. linux express 安装,linux下的node+express安装教程

    一. node安装教程 1. 查看文件夹 [root@VM_60_135_centos node]# ls ###myblog node-v10.16.0-linux-x64.tar.xz 2. 解压 ...

  8. linux下qt的文件打包,【最详细最完整】在Linux 下如何打包免安装的QT程序?

    版权声明:嵌入式linux相关的文章是我的学习笔记,基于Exynos 4412开发板,一部分内容是总结,一部分是查资料所得,大家可以自由转载,但请注明出处! https://blog.csdn.net ...

  9. php rdkafka实例,linux下php扩展kafka的实例分享

    本文主要和大家分享linux下php扩展kafka的实例,希望能帮助到大家. 1.安装librdkafkawget https://github.com/edenhill/librdkafka/arc ...

最新文章

  1. c语言二叉树最小值,C语言递归之二叉树的最小深度
  2. maven打包跳过测试
  3. Unsupported major.minor version 51.0(jdk版本错误)
  4. 携程Apollo(阿波罗)配置中心在.NET Core项目快速集成
  5. 前端学习(1669):前端系列实战课程之半透明拖拽思路
  6. 【Python】万花筒
  7. Linux 多线程应用中如何编写安全的信号处理函数
  8. Visual Leak Detector 2.2.3 Visual C++内存检测工具
  9. c语言编程怎么记,新手如何学习c语言
  10. STM32_编程入门
  11. libcef和js交互
  12. 台式计算机无线网经常掉线,台式机无线上网经常断网怎么办呢
  13. 2.19 serenity
  14. Markdown的常用语法(个人总结)
  15. 劳动合同与聘用合同的区别
  16. 豆瓣首页话题输入框的实现
  17. 几种常用的mosfet驱动电路
  18. linux中解压rar文件
  19. 【线段树】【扫描线】小睿睿的方案
  20. 计算机网络stp和utp,网线STP和UTP有什么区别

热门文章

  1. 感动中国感动谁(转)
  2. 原生js实现吸顶效果
  3. 蓝桥杯STEAM测试python2022一月测试题第五题
  4. linux shell对行数进行统计的方法
  5. Java 读入单个字符方法
  6. 各银行的英文缩写,及其意义
  7. Python OpenCV 图片高斯模糊
  8. 章节三:RASA Domain介绍
  9. MongoDB的安装到使用 + Python操作MongoDB + 有关系和无关系数据库比较
  10. Java大牛呕心沥血经历—谈薪资技巧(谁看了不说一句666)