使用PHP的ProtoBuf扩展

扩展使用的是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) {即可。

标签: PHP, protobuf

仅有一条评论

  1. hi hi

    最近使用protobuf遇到点问题,可否请教

添加新评论