php protobuf 扩展支持(Docker)
protobuf安装
获取压缩包
1
wget https://github.com/protocolbuffers/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz
解压
1
tar zxvf protobuf-2.6.1.tar.gz
编译
1
2cd protobuf-2.6.1
./configure --prefix=/usr/local/protobufmake 安装
1
make && make install
加入到环境变量
1
export PATH=/usr/local/protobuf/bin:$PATH
验证是否安装ok,显示相应版本号
1
protoc --version
php protobuf扩展安装
获取压缩包
1
wget https://github.com/allegro/php-protobuf/archive/master.zip
解压
1
unzip master.zip
使用phpize对php进行添加扩展
1
phpize
编译
1
./configure --with-php-config=/www/server/php/71/bin/php-config
make 安装
1
make && make install
编辑php.ini文件,添加一行
1
echo 'extension=protobuf.so' >> /www/server/php/71/etc/php.ini
重启php与nginx
composer
- 安装php-protobuf
1
2
3cd /${PATH}/php-protobuf-master
curl -s http://getcomposer.org/installer | php
php composer.phar install
修改源代码
打开 PhpGenerator.php
1
2cd /${PATH}/php-protobuf-master
vim src/Allegro/Protobuf/Compiler/PhpGenerator.php修改 _createFileComment 函数,注释一行代码
1
//$comment->append('Auto generated from ' . basename($file->getName()) . ' at ' . $date);
修改 _describeSingleField 函数,在
$comment = new CommentStringBuffer(self::TAB, self::EOL);
之前设置$returnCast
为空字符串(约 687 行)1
2$returnCast = '';//新增的一行
$comment = new CommentStringBuffer(self::TAB, self::EOL);
protobuf使用
- 编译生成代码到指定目录
1
php /root/php-protobuf-master/protoc-gen-php.php -o protobuf_msg/ miqu.proto
命令行选项
- -o out, 生成文件的目标目录(默认为当前目录).
- -I proto_path, 要在其中搜索导入的目录。
- –protoc=protoc 原编译器的可执行路径。