How to process protocol buffers data in PHP

Source: Internet
Author: User
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 ');
  • Related Article

    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.