如何在PHP中處理Protocol Buffers數據大綱
我們知道Protocol Buffers是Google定義的一種跨語言、跨平臺、可擴展的數據傳輸及存儲的協議,因爲將字段協議分別放在傳輸兩端,傳輸數據中只包含數據本身,不需要包含字段說明,所以傳輸數據量小,解析效率高。感興趣的可以訪問。Protocol Buffers官方只支持C++, Java, Python, C#, Go,如果想在PHP中使用Protocol Buffers,需要藉助於第三方的擴展,使用方法如下。下面是小編爲大家帶來的關於如何在PHP中處理Protocol Buffers數據的知識,歡迎閱讀。
安裝protoc編譯器
第一步,安裝Google的protoc編譯器,這個工具可以把proto文件中定義的Message轉換爲各種編程語言中的類。下載release版本直接編譯安裝。
tar -xvzf
cd protobuf-2.5.0
./configure --prefix=/usr/local/protobuf
make && make install
下載地址()
安裝PHP Plugin
第二步,安裝protoc的PHP plugin,需要使用composer安裝,感興趣的可以訪問
這個插件可以將proto文件轉換到PHP文件,在PHP應用中引用後,可以將二進制格式的Protocol Buffers數據轉換爲PHP的對象
unzip
cd protoc-gen-php-master
curl -sS | php
php install
/usr/local/protobuf/bin/protoc --plugin=bin/protoc-gen-php --php_out=php_kingso -I. o
下載地址()
安裝php-protocolbuffers
第三步,安裝php-protocolbuffers,這是一個PHP擴展,在第二步中已經完成了proto文件到PHP文件的`轉換,但是對PHP對象的各種操作還需要這個擴展中的API方法
phpize
./configure
make && make install
然後在你的配置文件中添加
extension = ""
下載地址()
編寫代碼
第四步,藉助上面提到的擴展的各種API方法,可以簡單地get出自己需要的字段完成後續工作
require "....../"
$ks_result = KSResult::parseFromString($kingso_res);
$ks_result->get('xxx_name');
相關文章
-
如何在PHP中處理Protocol Buffers數據
Protocol Buffers是Google定義的一種跨語言、跨平臺、可擴展的數據傳輸及存儲的協議,因爲將字段協議分別放在傳輸兩端,傳輸數據中只包含數據本身,不需要包含字段說明,所以傳輸數據量小,解析效率高。如何在PHP中處理Protoco -
PHP中CURL的CURLOPT-POSTFIELDS參數使用細節
CURL確實是一個不錯的好工具,不僅在PHP中還是其他的操作系統中,都是一個非常好用的。但是如果你有些參數沒有用好的話,那可能會得不到自己理想中的結果。具體情況如下,更多消息請關注應屆畢業生網! 在通常情況下,我 -
Efforts Urged to Improve Womens Reproductive Health英語閱讀
Efforts Urged to Improve Women's Reproductive HealthParliamentarians from over 100 countries are being urged to take action in improving women's reproductive health ahead of the 2015 deadline -
The Unforgettable School Trip英語作文
the unforgettable school triplast tuesday, i went to chimelong paradise with my classmates. i played many different and exciting games. we arrived there at about 9 o’clock. there were 3 people in my -
用Photoshop如何繪製Google Currents圖標
使用Photoshop如何繪製 Google Currents 的圖標?下面是詳細介紹,歡迎閱讀,更多內容請關注應屆畢業生網!這題用 AI、Sketch 等矢量繪圖工具來做,可能比 Photoshop 合適。以下過程使用 Sketch 繪製,其他軟件可觸類旁通。一 -
英語作文Let the Surprise Speak of Your Love
In China, people are not used to saying out the word “love”, they don’t express their emotion strongly, it is Chinese tradition, people believe that deep love should be proved in action instead of -
淺談php中curl和fsockopen的應用
php中curl、fsockopen有什麼作用呢?下面小編就爲大家帶來一篇淺談php中curl、fsockopen的應用。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧!最近要用到通過post上傳文件,網上盛傳的有cu -
英語美文:Bush, watch out for the pretzels
Moore tells Bush: watch out for the pretzelsAFTER winning the top prize at Cannes for his anti—Bush documentary. US filmmaker Michael Moore said he hoped the President had not been eating a pretzel wh -
Jolie drops battle over perfume named Shilohy英語作文
angelina jolie has dropped her legal battle with a perfume-maker who had named her fragrance shiloh - the same as jolies youngest daughter.jolie had filed a note with the u.s. patent and trademark off -
少兒英語小故事:She Practices Flips for the Olympic
She does handstands. She does cartwheels. She does flips. She does back flips and front flips. She does somersaults. She trains every day. She is a gymnast. She practices for the Olympics. The Olympic