1、 Update Centos7 download source
Remember to backup before updating! ! !
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
Reference: http://mirrors.aliyun.com/help/centos
163 Source reference: http://mirrors.163.com/.help/centos.html
2、 Install epel source
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
If the version is not the same, go here to find http://dl.fedoraproject.org/pub/epel/
rpm -ivh rpm epel-release-7-8.noarch.rpm
yum clean all
yum update
yum makecache
3、 Install PHP environment
4、 Install composer
curl -sS https://getcomposer.org/installer | php — –install-dir=/usr/local/bin/
mv /usr/local/bin/composer.phar /usr/local/bin/composer
5、 Install protobuf
yum install php-devel
git clone https://github.com/allegro/php-protobuf.git
cd php-protobuf
yum -y install gcc
yum -y install gcc-c++
yum install make
phpize
. /configure
make && make install
Installing shared extensions: /usr/lib64/php/modules/
composer install
vi /etc/php.ini
Finally add
extension=protobuf.so
7、 Install protoc
wget https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz
cd protobuf-2.6.1
. /configure
make
make install
Enter protoc --version
libprotoc 2.6.1
The installation is successful
8、 Test Case
touch foo.proto
Write the following
message Foo
{
required int32 bar = 1;
optional string baz = 2;
repeated float spam = 3;
}
generate
php /root/soft/php-protobuf/protoc-gen-php.php foo.proto
Write the case test.php
setBar(1);
$foo->setBaz('two');
$foo->appendSpam(3.0);
$foo->appendSpam(4.0);
$packed = $foo->serializeToString();
$parsedFoo =newFoo();try{
$parsedFoo->parseFromString($packed);}catch(Exception $ex){die('Oops.. there is a bug in this example, '. $ex->getMessage());}
$parsedFoo->dump();
Execution case
php -f test.php
Foo {1: bar =>12: baz =>"two"3:spam(2)=>[0]=>3[1]=>4}
Recommended Posts