使用PHP的ProtoBuf扩展

来自:互联网
时间:2019-08-23
阅读:

扩展使用的是allegro/php-protobuf,地址见github.

1、下载源码。

2、编译安装。

  /usr/local/php/bin/phpize
  ./configure --with-php-config=/usr/local/php/bin/php-config
  make && make install

3、执行下面的命令,生成对应的PHP类文件。

/usr/local/php/bin/php ./protoc-gen-php.php ./qcloud_notify.protofg

在第三步生成文件时,遇到下面的错误。

1、报Unable to find the protoc command.的错误。

解决办法:

1. 下载protobuf源码。(allegro/php-protobuf要求protobuf版本最低为2.6,我下载的2.6版本)

2. 编译安装。

  sh ./autogen.sh
  ./configure
  make && make install

2、提示ERROR: protoc exited with an exit status when executed with。

解决办法:

编辑src/Allegro/Protobuf/Compiler/Compiler.php文件.

找到148行

if ($return !== 0) {,

改为

if ($return != 0) {

即可。

返回顶部
顶部