系统环境:Ubuntu
PHP:7.3
需要安装工具
-
protoc: 将proto文件生成为php文件的编译器
-
grpc_php_plugin: protoc生成关于grpc的php文件的插件
-
grpc.so: php的grpc扩展
-
protobuf.so: php的protobuf扩展
1. protobuf扩展安装:
github地址:https://github.com/allegro/php-protobuf/
git clone https://github.com/allegro/php-protobuf
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
修改php.ini
extension = protobuf.so
2. 安装protoc:
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.18.0/protoc-3.18.0-linux-x86_64.zip
unzip protoc-3.18.0-linux-x86_64.zip -d protoc
cp -rf ./protoc/bin ./protoc/include /usr/local
protoc --version
编译:
apt-get install libtool
git clone https://github.com/grpc/grpc
cd grpc
git submodule update --init
EXTRA_DEFINES=GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK make
3. 安装php GRPC扩展:
cd grpc
grpc_root="$(pwd)"
cd src/php/ext/grpc
/usr/local/php/bin/phpize
GRPC_LIB_SUBDIR=libs/opt ./configure --with-php-config=/usr/local/php/bin/php-config --enable-grpc="${grpc_root}"
make
make install
修改php.ini
extension = grpc.so
系统安装grpc_php_plugin插件:
cd grpc
mkdir -p cmake/build
cd cmake/build
cmake ../..
make protoc grpc_php_plugin
编译好的文件在
/soft/grpc/cmake/build/grpc_php_plugin