最近接触到需要使用google的Protocol Buffers数据传输,特作记录如下:

一、安装

参考github的开源扩展:https://github.com/allegro/php-protobuf/ 以下的“使用”是翻译自该说明文档

克隆代码

  1. git clone https://github.com/allegro/php-protobuf

进入代码目录

  1. cd php-protobuf

编译安装 PHP 扩展 (可参考: php.net)

  1. $ phpize
  2. $ ./configure
  3. $ make
  4. $ sudo make install

这里默认安装到了

  1. 可能会报错:Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.

原因:缺少autoconf,安装之!

  1. $ sudo apt-get install autoconf

开启PHP扩展

  1. # 请把下行代码添加到你的 php.ini
  2. extension=protobuf.so

分类: web

标签:   linux