总结
豆包 AI 助手文章总结

Linux下给PHP安装amqp扩展 linux 安装php7 php安装 centos php安

php中文网
发布: 2016-07-29 08:50:13
原创
1643人浏览过

本文介绍了在linux下给php安装amqp扩展的过程,有需要的朋友可以关注一下。

安装librabbitmq-c和rabbitmq-codegen

# 下载0-9-1版的rabbitmq-c
git clone git://github.com/alanxz/rabbitmq-c.git
cd rabbitmq-c
# Enable and update the codegen git submodule
git submodule init
git submodule update
# Configure, compile and install
autoreconf -i && ./configure && make && sudo make install
登录后复制

安装pecl扩展

#下载最新的amqp扩展
wget http://pecl.php.net/get/amqp-1.0.9.tgz
tar xvzf amqp-1.0.9.tgz
cd amqp-1.0.9 && phpize
./configure --with-amqp && make && sudo make install
登录后复制

记得在php.ini中加入amqp扩展:

extension=amqp.so
登录后复制

安装过程中可能会遇到的问题

立即学习PHP免费学习笔记(深入)”;

1、缺少libtool包

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,ubuntu:

sudo apt-get install libtool
登录后复制

其他系统类似

2、如果还有其他问题,欢迎给我留言,我补上

使用

<?php
//配置信息
$conn_args = array(
    'host' => '127.0.0.1',
    'port' => '5672',
    'login' => 'guest',
    'password' => 'guest',
    'vhost'=>'/'
);
//创建连接
$conn = new AMQPConnection($conn_args);
if (!$conn->connect()) {
    die('Not connected @@##@@ ' . PHP_EOL);
}
// Open Channel
$channel = new AMQPChannel($conn);
// Declare exchange
$exchange = new AMQPExchange($channel);
$exchange->setName('extest');
$exchange->setType('fanout');
$exchange->declare();
// Create Queue
$queue = new AMQPQueue($channel);
$queue->setName('qutest');
$queue->declare();
// Bind it on the exchange to routing.key
$exchange->bind('qutest', 'routing.key');
$data = array(
    'Name' => 'foobar',
    'Args'  => array("0", "1", "2", "3"),
);
//生产者,向RabbitMQ发送消息
$message = $exchange->publish(json_encode($data), 'key');
if (!$message) {
    echo 'Message not sent', PHP_EOL;
} else {
    echo 'Message sent!', PHP_EOL;
}
//消费者
while ($envelope = $queue->get(AMQP_AUTOACK)) {
    echo ($envelope->isRedelivery()) ? 'Redelivery' : 'New Message';
    echo PHP_EOL;
    echo $envelope->getBody(), PHP_EOL;
}
?>
登录后复制

以上就介绍了Linux下给PHP安装amqp扩展,包括了Linux,php安装方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

linux 安装php,linux php,php,linux php环境搭建,linux php安装教程,linux安装php环境,linux 安装php7,php安装,centos php安
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
豆包 AI 助手文章总结
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号