Protocol buffers is a cross-lingual, cross-platform, extensible data transfer and storage protocol defined by Google, because the field protocol is placed on both ends of the transmission, the data contained in the transfer data itself, do not need to include the field description, so the volume of data transmission is small, high resolution efficiency. Interested can be accessed here. Protocol buffers Official only supports C + +, Java, Python, C #, Go, if you want to use Protocol buffers in PHP, you need to use third-party extensions, using the following method.
Installing the PROTOC Compiler
The first step is to install Google's Protoc compiler, which converts the message defined in the proto file into a class in a variety of programming languages. Download release release to compile the installation directly.
Shell
TAR-XVZF protobuf-2.5. 0 . TAR.GZCD protobuf-2.5. 0 . /configure--prefix=/usr/local/&& make install
Install PHP Plugin
The second step, install Protoc PHP plugin, need to use composer installation, interested in can access http://www.phpcomposer.com.
This plugin can convert the proto file to a php file that can be referenced in a PHP application to convert binary formatted protocol buffers data to PHP objects
Shell
Unzip protoc-gen-php-master.zipcd protoc-gen-php--ss https://Getcomposer.org/installer | PHPphp composer.phar install/usr/local/protobuf/bin/protoc--plugin=bin/protoc-gen-php--php_out=php _kingso-i. Kingso.proto
Installing Php-protocolbuffers
The third step, install Php-protocolbuffers, this is a php extension, in the second step has completed the proto file to php file conversion, but the various operations of the PHP object also need this extension of the API method
Shell
phpize. /&& make install
Then add it in your php.ini profile.
Shell
" protocolbuffers.so "
Writing code
Fourth, with the extension of the above mentioned various API methods, you can simply get out of the fields you need to complete the follow-up work
Shell
" .../kingso.proto.php " = ksresult::p arsefromstring ($kingso _res); $ks _result,get('xxx_name ');
How to process Protocol buffers data in PHP