jwj 发布的文章

TP框架的column数据库查询方法是一个非常方便的快捷查询方法,可以用该方法快速的返回结果集中的列,并且可以指定字段作为数据集的数组下标。但是在使用SQL函数后,却异常的返回了索引数组,而不是想要的关联数组。

我想查询本月每天的总营业额,所以使用了以下的方法查询

Db::table('ledger')->where('create_time', 'between', ['2020-01-01', '2020-01-31'])->group('DATE_FORMAT(ledger_date, "%m-%d")')->column('SUM(amount)', 'DATE_FORMAT(ledger_date, "%m-%d")')

我理想中的结果应该是

[
    [01-01] => 100.00,
    [01-02] => 200.00,
    [01-03] => 210.00,
    ...
]

但结果却是

[
    0 => 100.00,
    1 => 200.00,
    2 => 210.00,
    ...
]

这不对劲啊,怎么返回了索引数组,不是关联数组?
然后就看代码,断点调试,终于发现了问题,竟然是一个小小的空格导致的!!!
原来,我使用了SQL函数

DATE_FORMAT(ledger_date, "%m-%d")

然后TP框架在处理SQL列名称的时候,会以,分割列名称,然后使用trim来去除空格

$field = array_map('trim', explode(',', $field));

所以实际去查询的时候,列名称,两边的空格都被去除了,变成了

SELECT DATE_FORMAT(ledger_date,"%m-%d"),SUM(amount) FROM `ledger` ....

但是索引的字段名没变,所以最终

DATE_FORMAT(ledger_date, "%m-%d")

不等于

DATE_FORMAT(ledger_date,"%m-%d")

导致没能生成关联数组

最终的解决方法是,我们使用之前就把逗号两边的空格都去掉,就能得到自己想要的了。

Db::table('ledger')->where('create_time', 'between', ['2020-01-01', '2020-01-31'])->group('DATE_FORMAT(ledger_date,"%m-%d")')->column('SUM(amount)', 'DATE_FORMAT(ledger_date,"%m-%d")')

最近刚好用上模型事件,但手册上对事件的触发条件却没有详细的进行说明。那么,就只能自己进行测试了。

模型事件

首先,从手册上,我们可以知道模型支持以下事件:

事件描述事件方法名
after_read查询后onAfterRead
before_insert新增前onBeforeInsert
after_insert新增后onAfterInsert
before_update更新前onBeforeUpdate
after_update更新后onAfterUpdate
before_write写入前onBeforeWrite
after_write写入后onAfterWrite
before_delete删除前onBeforeDelete
after_delete删除后onAfterDelete
before_restore恢复前onBeforeRestore
after_restore恢复后onAfterRestore

建立模型

为了了解每个事件的触发条件,我们先建立以下模型

模型代码app/model/Users.php

<?php
namespace app\model;

use think\Model;
use think\model\concern\SoftDelete;

class Users extends Model
{
    // 软删除
    use SoftDelete;

    public static function onAfterRead($user) {
        dump('查询后');
    }

    public static function onBeforeInsert($user) {
        dump('新增前');
    }

    public static function onAfterInsert($user) {
        dump('新增后');
    }

    public static function onBeforeUpdate($user) {
        dump('更新前');
    }

    public static function onAfterUpdate($user) {
        dump('更新后');
    }

    public static function onBeforeWrite($user) {
        dump('写入前');
    }

    public static function onAfterWrite($user) {
        dump('写入后');
    }

    public static function onBeforeDelete($user) {
        dump('删除前');
    }

    public static function onAfterDelete($user) {
        dump('删除后');
    }

    public static function onBeforeRestore($user) {
        dump('恢复前');
    }

    public static function onAfterRestore($user) {
        dump('恢复后');
    }
}

数据表

CREATE TABLE `users` (
 `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
 `name` varchar(32) NOT NULL COMMENT '姓名',
 `area` varchar(32) NOT NULL COMMENT '区域',
 `address` varchar(64) NOT NULL COMMENT '地址',
 `balance` decimal(9,2) NOT NULL COMMENT '余额',
 `password` varchar(255) NOT NULL COMMENT '密码',
 `status` int(11) NOT NULL COMMENT '状态',
 `last` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后活跃时间',
 `phone` varchar(11) NOT NULL COMMENT '手机号',
 `delete_time` int(10) unsigned DEFAULT NULL COMMENT '删除时间',
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='用户表'

测试代码

代码

然后通过以下代码去操作数据库

use \app\model\Users;
$data = [
    'name' => 'test',
    'phone' => '13888888888',
    'area' => '0',
    'address' => '广东省韶关市',
    'balance' => '0',
    'password' => '0',
    'status' => '0',
    'last' => '2019-01-01 00:00:00',
];

dump('Users::create($data)');
$users = Users::create($data);

dump('Users::insert($data)');
Users::insert($data);

dump('Users::where("id", $users["id"])->update(["area" => 1])');
Users::where("id", $users["id"])->update(["area" => 1]);

dump('Users::update(["area" => 1], ["id" => $users["id"]])');
Users::update(["area" => 1], ["id" => $users["id"]]);

dump('$users->save(["area" => 2])');
$users->save(["area" => 2]);

dump('Users::where("id", $users["id"])->delete()');
Users::where("id", $users["id"])->delete();

dump('Users::where("id", ">", 0)->find()');
$users = Users::where("id", ">", 0)->find();

dump('Users::destroy($users["id"])');
Users::destroy($users["id"]);

dump('$users->restore()');
$users->restore();

dump('$users->delete()');
$users->delete();

执行结果

执行之后,返回以下结果

^ "Users::create($data)"
^ "写入前"
^ "新增前"
^ "新增后"
^ "写入后"
^ "Users::insert($data)"
^ "Users::where("id", $users["id"])->update(["area" => 1])"
^ "Users::update(["area" => 1], ["id" => $users["id"]])"
^ "写入前"
^ "更新前"
^ "更新后"
^ "写入后"
^ "$users->save(["area" => 2])"
^ "写入前"
^ "更新前"
^ "更新后"
^ "写入后"
^ "Users::where("id", $users["id"])->delete()"
^ "Users::where("id", ">", 0)->find()"
^ "查询后"
^ "Users::destroy($users["id"])"
^ "查询后"
^ "删除前"
^ "删除后"
^ "$users->restore()"
^ "恢复前"
^ "恢复后"
^ "$users->delete()"
^ "删除前"
^ "删除后"

总结

方法查询后新增前新增后更新前更新后写入前写入后删除前删除后恢复前恢复后
create()
insert()
update()
save()
delete()
find()
destroy()
restore()

create()

模型创建数据方法,会触发写入前新增前新增后写入后。使用模型的save()saveAll()来新增方法也会触发这几个事件。

insert()

insert()是Db类的方法,不是模型方法,不会触发模型事件。

update()

update()是Db类的方法,不是模型方法,不会触发模型事件。

如果是模型静态调用update(),则执行的是模型的update方法,而模型的update方法会调用save()方法,所以跟模型的save()方法一样,会触发写入前更新前更新后写入后事件
感谢 @dejavu 的提醒

save()

使用模型的save()方法来更新数据,会触发写入前更新前更新后写入后事件。

delete()

如果是使用模型方法查询出来数据,然后再删除数据,则会触发删除前删除后事件。
如果是直接使用条件删除,则不会触发模型事件。因为直接使用条件删除,这时候的delete()方法不是模型方法。

find()

该查询方法会触发查询后事件

destroy()

该删除数据方法会触发查询后删除前删除后。所以,该方法是先查询出数据,然后再删除该数据。

restore()

该软删除恢复方法会触发恢复前恢复后方法

在接触一些thinkphp新手时,发现总是有一部分人不会使用composer来安装扩展包。于是他们就按照tp3的方式来下载扩展包的压缩包,然后将扩展包解压到项目里面去,结果最后发现用不了,提示类不存在Class 'EasyWeChat\Factory not found`。这里主要下,如何在thinkphp的项目里使用composer来安装扩展包,助力下这部分"迷途的人"。

安装composer

安装composer的方法网上已经很多了,所以这里就不重复去说了。但是要注意电脑里的php版本不要太低,建议使用php7.2
参考方法:https://www.runoob.com/w3cnote/composer-install-and-usage.html

使用composer安装扩展包

现今的9102年,大多数的php扩展包都支持使用composer来进行安装,所以会composer的使用已经算是一项非常必要的技能了,就跟学会复制黏贴一样重要。
下面就以安装PHPMailer为例。

1.获取composer安装命令

打开PHPMailerGitHub,在它的文档里能看到一条composer的命令,一般在支持composer安装的扩展包文档里都会包含这个命令,命令以composer require开头,后面跟着扩展包的“名称”。
命令:

composer require phpmailer/phpmailer

2.打开命令行,并切换到项目目录

首先,这里假设我们的项目放在了E:/wwwroot/www.ll00.cn,打开这个目录能看到config extend public route runtime vendor等目录。
然后打开命令行,输入E:切换到E盘,再输入cd E:/wwwroot/www.ll00.cn切换到项目目录

不要将运行目录切换到public或者vender,我看很多人都犯这样的错误
E:
cd E:/wwwroot/www.ll00.cn

3.执行composer安装命令

安装命令我们已经在第一步获取到了,并且命令行也将运行目录切换到了项目目录里,这时候就可以执行composer命令来安装扩展包了

composer require phpmailer/phpmailer

到这里,如无意外,扩展包就安装好了

使用扩展包

以下是在项目里使用PHPMailer的示例代码

<?php
// 导入 PHPMailer 类到当前命名空间
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

// 实例化PHPMailer
$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      // Enable verbose debug output
    $mail->isSMTP();                                            // Send using SMTP
    $mail->Host       = 'smtp1.example.com';                    // Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
    $mail->Username   = 'user@example.com';                     // SMTP username
    $mail->Password   = 'secret';                               // SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
    $mail->Port       = 587;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('from@example.com', 'Mailer');
    $mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
    $mail->addAddress('ellen@example.com');               // Name is optional
    $mail->addReplyTo('info@example.com', 'Information');
    $mail->addCC('cc@example.com');
    $mail->addBCC('bcc@example.com');

    // Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

TP6的文件上传相较于之前的版本有些变化,用法变了,也相对的更灵活了。下面是文件上传的使用示例。
还算说得挺清楚的了,如果还有什么疑问,可以在评论区留言。

前端代码

<!-- 请注意换一下action的提交地址,这里使用了URL生成的助手函数,参考https://www.kancloud.cn/manual/thinkphp6_0/1037508 -->
<form action="{:url('Upload/index')}" method="post" enctype="multipart/form-data">
    <!-- 文件选择按钮 -->
    <input type="file" name="file">
    <!-- 表单提交按钮 -->
    <button type="submit">提交</button>
</form>

配置文件

路径:/config/filesystem.php

<?php

use think\facade\Env;

return [
    // 默认磁盘
    'default' => Env::get('filesystem.driver', 'local'),
    // 磁盘列表
    'disks'   => [
        'local'  => [
            'type' => 'local',
            'root' => app()->getRuntimePath() . 'storage',
        ],
        'public' => [
            // 磁盘类型
            'type'       => 'local',
            // 磁盘路径
            'root'       => app()->getRootPath() . 'public/storage',
            // 磁盘路径对应的外部URL路径
            'url'        => '/storage',
            // 可见性:public=公共,private=私有
            'visibility' => 'public',
        ],
        // 更多的磁盘配置信息
    ],
];

上传处理代码

// 上传文件错误或者文件验证不通过时,都会抛出异常,所以要使用try来捕捉异常
try {
    // 获取上传的文件,如果有上传错误,会抛出异常
    $file = \think\facade\Request::file('file');
    // 如果上传的文件为null,手动抛出一个异常,统一处理异常
    if (null === $file) {
        // 异常代码使用UPLOAD_ERR_NO_FILE常量,方便需要进一步处理异常时使用
        throw new \Exception('请上传文件', UPLOAD_ERR_NO_FILE);
    }

    // 使用验证器验证上传的文件
    validate(['file' => [
        // 限制文件大小(单位b),这里限制为4M
        'fileSize' => 4 * 1024 * 1024,
        // 限制文件后缀,多个后缀以英文逗号分割
        'fileExt'  => 'gif,jpg,png'
        // 更多规则请看“上传验证”的规则,文档地址https://www.kancloud.cn/manual/thinkphp6_0/1037629#_444
    ]])->check(['file' => $file]);

    // 保存路径,实际保存路径为“磁盘路径” + “avatar”
    $path = 'avatar';
    // 文件名规则,默认是当前时间。可以使用哈希算法,如:md5/sha1等,还可以传入匿名函数,详细可以看后面
    $rule = 'md5';
    // 将文件保存public磁盘,文件名为$rule指定的规则。然后将文件路径赋值给$path
    $path = \think\facade\Filesystem::disk('public')->putFile($path, $file, $rule);
    // 拼接URL路径
    $url = \think\facade\Filesystem::getDiskConfig('public', 'url') . '/' . str_replace('\\', '/', $path);
} catch (\Exception $e) {
    // 如果上传时有异常,会执行这里的代码,可以在这里处理异常
    return json([
        'code' => 1,
        'msg'  => $e->getMessage(),
    ]);
}

$info = [
    // 文件路径:avatar/a4/e7b9e4ce42e2097b0df2feb8832d28.jpg
    'path' => $path,
    // URL路径:/storage/avatar/a4/e7b9e4ce42e2097b0df2feb8832d28.jpg
    'url'  => $url,
    // 文件大小(字节)
    'size' => $file->getSize(),
    // 文件名:读书顶个鸟用.jpg
    'name' => $file->getFilename(),
    // 文件MINE:image/jpeg
    'mime' => $file->getMime(),
];
halt($info);

文件名规则

文件名规则支持传入匿名函数、哈希算法和函数名。默认情况下,使用时间来自动生成。

默认算法

默认情况下,文件名是这样生成的

date('Ymd') . DIRECTORY_SEPARATOR . md5((string) microtime(true))

结果是

/storage/avatar/20200117/2801a4c6c49a1e411f58abfa9b4a8f52.jpg

匿名函数

/**
 * @param \think\file\UploadedFile $file 文件
 * @return string 文件名
 */
$rule = function(\think\file\UploadedFile $file) {
    // 获取获取上传文件类型信息:image/jpeg
    $file->getOriginalMime();
    // 获取上传文件名:读书顶个鸟用.jpg
    $file->getOriginalName();
    // 获取文件扩展名:jpg
    $file->extension();
    // 获取文件的哈希散列值
    $file->hash();

    return $file->hash('md5');
};
$path = \think\facade\Filesystem::disk('public')->putFile($path, $file, $rule);

结果是

/storage/avatar/a4e7b9e4ce42e2097b0df2feb8832d28.jpg

哈希算法

支持传入hash_algos()里支持的算法,如md5,sha1,sha256

$rule = 'sha1';
$path = \think\facade\Filesystem::disk('public')->putFile($path, $file, $rule);

结果是

/storage/avatar/ef/c6e7f357b7f97cb7ccfa7c5cfe83bf9819f88f.jpg

使用哈希算法会自动取文件哈希值前两个字符作为目录名

函数名

这里传入time,还可以传入自定义函数名或php内置函数名。但只支持可不传参数的函数

$rule = 'time';
$path = \think\facade\Filesystem::disk('public')->putFile($path, $file, $rule);

结果是

/storage/avatar/1579228212.jpg

因业务需要需要使用MQ,需要用到amqp,但现在所使用的PHP环境没有装这个扩展,参考segmentfault里的一篇教程进行安装,整理出了下面的教程。在这里,感谢@一个向往前端的后端工程师

安装rabbitmq-c

在安装amqp之前还需要安装另外一个通讯扩展rabbitmq-c。

下载源代码

最新源代码地址可以从github获取,这里用的是v0.10.0版本(发布本教程时最新版)

wget https://github.com/alanxz/rabbitmq-c/archive/v0.10.0.zip

解压源代码并转到源代码目录

unzip v0.10.0.zip && cd rabbitmq-c-0.10.0

让cmake根据CMakeList.txt创建Makefile文件

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/rabbitmq-c .

执行结果

-- The C compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- CMAKE_BUILD_TYPE not specified. Creating Release build
-- Found C inline keyword: inline
-- Looking for getaddrinfo
-- Looking for getaddrinfo - found
-- Looking for socket
-- Looking for socket - found
-- Looking for poll
-- Looking for poll - found
-- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - found
-- Looking for posix_spawnp in rt
-- Looking for posix_spawnp in rt - found
-- Found OpenSSL: /usr/lib64/libssl.so;/usr/lib64/libcrypto.so (found suitable version "1.0.2k", minimum required is "0.9.8")
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Performing Test HAVE_GNU90
-- Performing Test HAVE_GNU90 - Success
-- Could NOT find POPT (missing:  POPT_INCLUDE_DIR POPT_LIBRARY)
-- Could NOT find XMLTO (missing:  XMLTO_EXECUTABLE)
-- Could NOT find Doxygen (missing:  DOXYGEN_EXECUTABLE)
-- Building rabbitmq as a shared library - yes
-- Building rabbitmq as a static library - yes
-- Configuring done
-- Generating done
-- Build files have been written to: /root/rabbitmq-c-0.10.0

开始编译rabbitmq-c库

cmake --build . --target install

执行结果

Scanning dependencies of target rabbitmq
[  1%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_framing.c.o
[  2%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_api.c.o
[  4%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_connection.c.o
[  5%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_mem.c.o
[  7%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_socket.c.o
[  8%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_table.c.o
[ 10%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_url.c.o
[ 11%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_tcp_socket.c.o
[ 13%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_time.c.o
[ 14%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_consumer.c.o
[ 15%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_openssl.c.o
[ 17%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_openssl_hostname_validation.c.o
[ 18%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_hostcheck.c.o
[ 20%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_openssl_bio.c.o
Linking C shared library librabbitmq.so
[ 20%] Built target rabbitmq
Scanning dependencies of target rabbitmq-static
[ 21%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_framing.c.o
[ 23%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_api.c.o
[ 24%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_connection.c.o
[ 26%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_mem.c.o
[ 27%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_socket.c.o
[ 28%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_table.c.o
[ 30%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_url.c.o
[ 31%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_tcp_socket.c.o
[ 33%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_time.c.o
[ 34%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_consumer.c.o
[ 36%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_openssl.c.o
[ 37%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_openssl_hostname_validation.c.o
[ 39%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_hostcheck.c.o
[ 40%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_openssl_bio.c.o
Linking C static library librabbitmq.a
[ 40%] Built target rabbitmq-static
Scanning dependencies of target amqp_bind
[ 42%] Building C object examples/CMakeFiles/amqp_bind.dir/amqp_bind.c.o
[ 43%] Building C object examples/CMakeFiles/amqp_bind.dir/utils.c.o
[ 44%] Building C object examples/CMakeFiles/amqp_bind.dir/unix/platform_utils.c.o
Linking C executable amqp_bind
[ 44%] Built target amqp_bind
Scanning dependencies of target amqp_connect_timeout
[ 46%] Building C object examples/CMakeFiles/amqp_connect_timeout.dir/amqp_connect_timeout.c.o
[ 47%] Building C object examples/CMakeFiles/amqp_connect_timeout.dir/utils.c.o
[ 49%] Building C object examples/CMakeFiles/amqp_connect_timeout.dir/unix/platform_utils.c.o
Linking C executable amqp_connect_timeout
[ 49%] Built target amqp_connect_timeout
Scanning dependencies of target amqp_consumer
[ 50%] Building C object examples/CMakeFiles/amqp_consumer.dir/amqp_consumer.c.o
[ 52%] Building C object examples/CMakeFiles/amqp_consumer.dir/utils.c.o
[ 53%] Building C object examples/CMakeFiles/amqp_consumer.dir/unix/platform_utils.c.o
Linking C executable amqp_consumer
[ 53%] Built target amqp_consumer
Scanning dependencies of target amqp_exchange_declare
[ 55%] Building C object examples/CMakeFiles/amqp_exchange_declare.dir/amqp_exchange_declare.c.o
[ 56%] Building C object examples/CMakeFiles/amqp_exchange_declare.dir/utils.c.o
[ 57%] Building C object examples/CMakeFiles/amqp_exchange_declare.dir/unix/platform_utils.c.o
Linking C executable amqp_exchange_declare
[ 57%] Built target amqp_exchange_declare
Scanning dependencies of target amqp_listen
[ 59%] Building C object examples/CMakeFiles/amqp_listen.dir/amqp_listen.c.o
[ 60%] Building C object examples/CMakeFiles/amqp_listen.dir/utils.c.o
[ 62%] Building C object examples/CMakeFiles/amqp_listen.dir/unix/platform_utils.c.o
Linking C executable amqp_listen
[ 62%] Built target amqp_listen
Scanning dependencies of target amqp_listenq
[ 63%] Building C object examples/CMakeFiles/amqp_listenq.dir/amqp_listenq.c.o
[ 65%] Building C object examples/CMakeFiles/amqp_listenq.dir/utils.c.o
[ 66%] Building C object examples/CMakeFiles/amqp_listenq.dir/unix/platform_utils.c.o
Linking C executable amqp_listenq
[ 66%] Built target amqp_listenq
Scanning dependencies of target amqp_producer
[ 68%] Building C object examples/CMakeFiles/amqp_producer.dir/amqp_producer.c.o
[ 69%] Building C object examples/CMakeFiles/amqp_producer.dir/utils.c.o
[ 71%] Building C object examples/CMakeFiles/amqp_producer.dir/unix/platform_utils.c.o
Linking C executable amqp_producer
[ 71%] Built target amqp_producer
Scanning dependencies of target amqp_rpc_sendstring_client
[ 72%] Building C object examples/CMakeFiles/amqp_rpc_sendstring_client.dir/amqp_rpc_sendstring_client.c.o
[ 73%] Building C object examples/CMakeFiles/amqp_rpc_sendstring_client.dir/utils.c.o
[ 75%] Building C object examples/CMakeFiles/amqp_rpc_sendstring_client.dir/unix/platform_utils.c.o
Linking C executable amqp_rpc_sendstring_client
[ 75%] Built target amqp_rpc_sendstring_client
Scanning dependencies of target amqp_sendstring
[ 76%] Building C object examples/CMakeFiles/amqp_sendstring.dir/amqp_sendstring.c.o
[ 78%] Building C object examples/CMakeFiles/amqp_sendstring.dir/utils.c.o
[ 79%] Building C object examples/CMakeFiles/amqp_sendstring.dir/unix/platform_utils.c.o
Linking C executable amqp_sendstring
[ 79%] Built target amqp_sendstring
Scanning dependencies of target amqp_ssl_connect
[ 81%] Building C object examples/CMakeFiles/amqp_ssl_connect.dir/amqp_ssl_connect.c.o
[ 82%] Building C object examples/CMakeFiles/amqp_ssl_connect.dir/utils.c.o
[ 84%] Building C object examples/CMakeFiles/amqp_ssl_connect.dir/unix/platform_utils.c.o
Linking C executable amqp_ssl_connect
[ 84%] Built target amqp_ssl_connect
Scanning dependencies of target amqp_unbind
[ 85%] Building C object examples/CMakeFiles/amqp_unbind.dir/amqp_unbind.c.o
[ 86%] Building C object examples/CMakeFiles/amqp_unbind.dir/utils.c.o
[ 88%] Building C object examples/CMakeFiles/amqp_unbind.dir/unix/platform_utils.c.o
Linking C executable amqp_unbind
[ 88%] Built target amqp_unbind
Scanning dependencies of target test_basic
[ 89%] Building C object tests/CMakeFiles/test_basic.dir/test_basic.c.o
Linking C executable test_basic
[ 89%] Built target test_basic
Scanning dependencies of target test_hostcheck
[ 91%] Building C object tests/CMakeFiles/test_hostcheck.dir/test_hostcheck.c.o
[ 92%] Building C object tests/CMakeFiles/test_hostcheck.dir/__/librabbitmq/amqp_hostcheck.c.o
Linking C executable test_hostcheck
[ 92%] Built target test_hostcheck
Scanning dependencies of target test_merge_capabilities
[ 94%] Building C object tests/CMakeFiles/test_merge_capabilities.dir/test_merge_capabilities.c.o
Linking C executable test_merge_capabilities
[ 94%] Built target test_merge_capabilities
Scanning dependencies of target test_parse_url
[ 95%] Building C object tests/CMakeFiles/test_parse_url.dir/test_parse_url.c.o
Linking C executable test_parse_url
[ 95%] Built target test_parse_url
Scanning dependencies of target test_sasl_mechanism
[ 97%] Building C object tests/CMakeFiles/test_sasl_mechanism.dir/test_sasl_mechanism.c.o
Linking C executable test_sasl_mechanism
[ 97%] Built target test_sasl_mechanism
Scanning dependencies of target test_status_enum
[ 98%] Building C object tests/CMakeFiles/test_status_enum.dir/test_status_enum.c.o
Linking C executable test_status_enum
[ 98%] Built target test_status_enum
Scanning dependencies of target test_tables
[100%] Building C object tests/CMakeFiles/test_tables.dir/test_tables.c.o
Linking C executable test_tables
[100%] Built target test_tables
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/rabbitmq-c/lib64/pkgconfig/librabbitmq.pc
-- Installing: /usr/local/rabbitmq-c/lib64/librabbitmq.so.4.4.0
-- Installing: /usr/local/rabbitmq-c/lib64/librabbitmq.so.4
-- Installing: /usr/local/rabbitmq-c/lib64/librabbitmq.so
-- Installing: /usr/local/rabbitmq-c/lib64/librabbitmq.a
-- Installing: /usr/local/rabbitmq-c/include/amqp.h
-- Installing: /usr/local/rabbitmq-c/include/amqp_framing.h
-- Installing: /usr/local/rabbitmq-c/include/amqp_tcp_socket.h
-- Installing: /usr/local/rabbitmq-c/include/amqp_ssl_socket.h

到这里就已经安装完成了。不过这里有一个坑。

软链接

你可以看一下/usr/local/rabbitmq-c下的目录只有include和lib64。因为后面编译安装amqp扩展的时候系统会到/usr/local/rabbitmq-c/lib目录下搜索依赖库,导致错误。所以这里需要加一步

ln -s /usr/local/rabbitmq-c/lib64 /usr/local/rabbitmq-c/lib

安装amqp扩展

下载源代码

最新源代码地址可以从PHP Pecl获取,这里用的是v1.9.4版本(发布本教程时最新版)

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

解压源代码并转到源代码目录

tar zxvf amqp-1.9.4.tgz && cd amqp-1.9.4

phpize

phpize 命令是用来准备 PHP 扩展库的编译环境的,主要是根据系统信息生成对应的configure文件。
宝塔支持同时使用多个PHP版本,所以注意这里的路径(/www/server/php/73/bin/phpize),换成你要添加的PHP版本对应的路径。

/www/server/php/73/bin/phpize

配置编译参数

宝塔支持同时使用多个PHP版本,所以注意这里的路径,换成你要添加的PHP版本对应的路径(/www/server/php/73/bin/php-config)。

./configure --with-php-config=/www/server/php/73/bin/php-config --with-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-c

执行结果

checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /www/server/php/73
checking for PHP includes... -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib
checking for PHP extension directory... /www/server/php/73/lib/php/extensions/no-debug-non-zts-20180731
checking for PHP installed headers prefix... /www/server/php/73/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking for amqp support... yes, shared
checking for amqp... yes, shared
checking for supported PHP versions... supported (7.3.13)
yes
checking for pkg-config... /usr/bin/pkg-config
checking for amqp files in default path... found in /usr/local/rabbitmq-c
checking for librabbitmq version... 0.10.0
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1572864
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h

开始编译安装

make && make install

执行结果

/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp.c -o amqp.lo
mkdir .libs
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp.c  -fPIC -DPIC -o .libs/amqp.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_type.c -o amqp_type.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_type.c  -fPIC -DPIC -o .libs/amqp_type.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_exchange.c -o amqp_exchange.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_exchange.c  -fPIC -DPIC -o .libs/amqp_exchange.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_queue.c -o amqp_queue.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_queue.c  -fPIC -DPIC -o .libs/amqp_queue.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_connection.c -o amqp_connection.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_connection.c  -fPIC -DPIC -o .libs/amqp_connection.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_connection_resource.c -o amqp_connection_resource.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_connection_resource.c  -fPIC -DPIC -o .libs/amqp_connection_resource.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_channel.c -o amqp_channel.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_channel.c  -fPIC -DPIC -o .libs/amqp_channel.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_envelope.c -o amqp_envelope.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_envelope.c  -fPIC -DPIC -o .libs/amqp_envelope.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_basic_properties.c -o amqp_basic_properties.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_basic_properties.c  -fPIC -DPIC -o .libs/amqp_basic_properties.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_methods_handling.c -o amqp_methods_handling.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_methods_handling.c  -fPIC -DPIC -o .libs/amqp_methods_handling.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_timestamp.c -o amqp_timestamp.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_timestamp.c  -fPIC -DPIC -o .libs/amqp_timestamp.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_decimal.c -o amqp_decimal.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_decimal.c  -fPIC -DPIC -o .libs/amqp_decimal.o
/bin/sh /root/amqp-1.9.4/libtool --mode=link cc -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2    -o amqp.la -export-dynamic -avoid-version -prefer-pic -module -rpath /root/amqp-1.9.4/modules  amqp.lo amqp_type.lo amqp_exchange.lo amqp_queue.lo amqp_connection.lo amqp_connection_resource.lo amqp_channel.lo amqp_envelope.lo amqp_basic_properties.lo amqp_methods_handling.lo amqp_timestamp.lo amqp_decimal.lo -Wl,-rpath,/usr/local/rabbitmq-c/lib -L/usr/local/rabbitmq-c/lib -lrabbitmq
cc -shared  .libs/amqp.o .libs/amqp_type.o .libs/amqp_exchange.o .libs/amqp_queue.o .libs/amqp_connection.o .libs/amqp_connection_resource.o .libs/amqp_channel.o .libs/amqp_envelope.o .libs/amqp_basic_properties.o .libs/amqp_methods_handling.o .libs/amqp_timestamp.o .libs/amqp_decimal.o  -L/usr/local/rabbitmq-c/lib -lrabbitmq  -Wl,-rpath -Wl,/usr/local/rabbitmq-c/lib -Wl,-soname -Wl,amqp.so -o .libs/amqp.so
creating amqp.la
(cd .libs && rm -f amqp.la && ln -s ../amqp.la amqp.la)
/bin/sh /root/amqp-1.9.4/libtool --mode=install cp ./amqp.la /root/amqp-1.9.4/modules
cp ./.libs/amqp.so /root/amqp-1.9.4/modules/amqp.so
cp ./.libs/amqp.lai /root/amqp-1.9.4/modules/amqp.la
PATH="$PATH:/sbin" ldconfig -n /root/amqp-1.9.4/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /root/amqp-1.9.4/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /www/server/php/73/lib/php/extensions/no-debug-non-zts-20180731/

启用扩展

配置php.ini

大概在配置文件九百多行的位置新建一行,加入以下代码

extension=/www/server/php/73/lib/php/extensions/no-debug-non-zts-20180731/amqp.so

重启php

重启php-fpm或重载配置

查看phpinfo()

查看phpinfo(),搜索amqp.host,如果找到基本就是安装成功。