php中使用google protobuf協議環境配置

需要安裝兩個東西

  • protoc編譯器
  • php-protobuf擴展

注意:protoc和php擴展的版本必須保持一致,這邊以V3.9.1爲例

網絡上很多文章,安裝了PHP擴展之後,還需要composer去加載,純屬誤導,擴展方式和composer二選一即可

 

安裝方法:

  • 安裝protoc

~# cd /data

~# wget -c https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/protoc-3.9.1-linux-x86_64.zip

~# unzip protoc-3.9.1-linux-x86_64.zip

~# cd bin/

~# mv protoc /usr/bin/ 

~# protoc --version

libprotoc 3.9.1

  •  安裝php-protobuf擴展 (擴展安裝和自己php安裝的路徑有關係,自己根據情況微調)

~# wget -c https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/protobuf-php-3.9.1.zip

~# unzip protobuf-php-3.9.1.zip

~# cd protobuf-3.9.1/php/ext/google/protobuf

~# /opt/php/bin/phpize

~# ./configure --with-php-config=/opt/php/bin/php-config

~# make

~# make install

phpinfo查看能看到:

protobuf

Version => 3.9.1

 到這邊,整個環境已順利配置完成

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章