We know that 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 transfer is small, high resolution efficiency. Interested can access the Https://developers.google.com/protocol-buffers/docs/overview. 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.
Tar-xvzf protobuf-2.5.0.tar.gzcd protobuf-2.5.0./configure--prefix=/usr/local/protobufmake && make install
Download Address
Install PHP Plugin
The second step, install Protoc PHP plugin, need to use composer installation, interested 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
Unzip PROTOC-GEN-PHP-MASTER.ZIPCD Protoc-gen-php-mastercurl-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
Download Address
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
Phpize./configuremake && make Install
Then add it in your php.ini profile.
Extension = "protocolbuffers.so"
Download Address
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
Require ".../kingso.proto.php" $ks _result = Ksresult::p arsefromstring ($kingso _res); $ks _result->get (' Xxx_ Name ');