How to process Protocol buffers data in PHP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.