Protocol Buffers 是一種輕便高效的結構化數據存儲格式,可用於結構化數據串行化,很適合作數據存儲或 RPC 數據交換格式。它可用於通信協議、數據存儲等領域的語言無關、平臺無關、可擴展的序列化結構數據格式。目前只提供了 C++、Java、Python 三種語言的 API。經過PHP-protobuf可實現,下面是本人的安裝經歷。php
1.centos環境
centos6.8
2.php環境
php-5.5.30
路徑
/usr/local/php-5.5.30
將protobuf和php-protobuf-master安裝在/usr/local下。html
apachec++
/usr/local/httpdgit
3.依賴包安裝
yum -y install php-pear php5-dev autoconf automake libtool make gcc gcc-c++github
4.安裝protobuf
protobuf-2.4.1.tar.gz
wget http://protobuf.googlecode.com/files/protobuf-2.4.1.tar.bz2
tar -jxvf protobuf-2.4.1.tar.bz2
cd protobuf-2.4.1/
./configure --with-php-config=/usr/local/php-5.5.30/bin/php-config
make
make installapache
5.master安裝
master.zip
wget https://github.com/allegro/php-protobuf/archive/master.zip
unzip master.zip
cd php-protobuf-master
/usr/local/php/bin/phpize #生成configure
./configure
make
make install
結果顯示 /usrb64/php/modules/表示安裝成功centos
ll /usrb64/php/modules/ui
vi /usr/local/php/etc/php.inigoogle
添加:spa
extension=/usr/lib64/php/modules/protobuf.so
重啓apache service httpd restart
6.執行語句驗證結果
在本文件路徑下透出test.proto,vitest.proto內容以下:
----------------------------------------------
message PhoneNumber {
required string number = 1;
required int32 type = 2;
}
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
repeated PhoneNumber phone = 4;
optional double money = 5;
}
message AddressBook {
repeated Person person = 1;
}
-------------------------------
protoc --plugin=/usr/local/php/bin/protoc-gen-php --php_out=. -I. tes1t.proto
生成test.php文件即表示成功。
參照鏈接地址:
http://www.hello1010.com/php-protobuf
http://www.cnblogs.com/brookin/p/4423692.html
http://www.cnblogs.com/taek/p/5470693.html