前言
准备工作可参考之前的文章:Windows 下编译 PHP Redis 扩展并支持 Igbinary 序列器
下载源码
下载地址:PECL :: Package :: protobuf
注意版本顺序,不是从最新到旧的
编写 config.w32
文件
进入桌面 pecl/protobuf-版本号
目录,新建文本文件:
ARG_ENABLE("protobuf", "whether to enable Protobuf extension", "no");
if (PHP_PROTOBUF != "no") {
var sources = "arena.c array.c convert.c def.c map.c message.c names.c php-upb.c protobuf.c third_party/utf8_range/naive.c third_party/utf8_range/range2-neon.c third_party/utf8_range/range2-sse.c";
var subdir = "\\third_party\\utf8_range";
ADD_SOURCES(configure_module_dirname + subdir, "\
naive.c \
range2-neon.c \
range2-sse.c \
", "protobuf");
EXTENSION("protobuf", sources);
}
完成后记得确保文件名为:config.w32
开始编译
buildconf
configure --disable-all --enable-cli --enable-cgi --enable-protobuf=shared --disable-zts
nmake
启用扩展
得到的文件在 php-版本号\x64\Release
里,将其扔到 PHP 安装目录 \ext
下,然后修改 php.ini
文件新增
extension=protobuf
保存后重启 PHP 相关服务即可