使用PHP的ProtoBuf扩展
扩展使用的是allegro/php-protobuf,地址见github.
- 下载源码。
- 编译安装。
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
- 执行下面的命令,生成对应的PHP类文件。
/usr/local/php/bin/php ./protoc-gen-php.php ./qcloud_notify.protofg
在第三步生成文件时,遇到下面的错误。
报
Unable to find the protoc command.
的错误。解决办法:
- 下载protobuf源码。(allegro/php-protobuf要求protobuf版本最低为2.6,我下载的2.6版本)
- 编译安装。
sh ./autogen.sh
./configure
make && make install
提示
ERROR: protoc exited with an exit status when executed with
。解决办法: 编辑`src/Allegro/Protobuf/Compiler/Compiler.php`文件. 找到148行`if ($return !== 0) {`,改为`if ($return != 0) {`即可。