本身本地环境本来有个PHP7.1的版本,结果在装grpc时一直提示没有权限把grpc.so拷贝到PHP扩展目录下,就从新装了一次phpphp
这次安装涉及的有:html
# 安装PHP brew intall php # 优先使用新安装的PHP7.2,即配置环境变量,这一步要注意本身的PHP目录,如下是个人目录 # 个人shell使用的是zsh,因此导入到~/.zshrc下,要注意本身的shell是什么,导入到本身使用的shell配置文件里 echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.zshrc # 使用配置文件,使其生效 source ~/.zshrc # 查看PHP的版本是不是本身安装的 php -v php-fpm -v
安装grpcnode
brew install grpc
安装PHP的grpc扩展git
git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc cd grpc git submodule update --init make sudo make install #这一步我本地报错找不到autolocal,查后须要安装automake,用brew install automake便可 cd grpc/src/php/ext/grpc phpize ./configure make sudo make install
以上都OK的话,在phpinfo里应该能够看到grpc的信息了github
pecl install protobuf
安装成功后,phpinfo里会有protobuf的信息.shell
下载examplenpm
$ # Clone the repository to get the example code: $ git clone -b v1.24.0 https://github.com/grpc/grpc $ # Build grpc_php_plugin to generate proto files if not build before $ cd grpc && git submodule update --init && make grpc_php_plugin $ # Navigate to the "hello, world" PHP example: $ cd examples/php $ ./greeter_proto_gen.sh $ composer install
我本地跑的是go的grpc服务端,因此不安装服务端了。demo里是用node作服务端。以下:composer
$ npm install $ cd dynamic_codegen $ node greeter_server.js
运行PHP的客户端:curl
$ ./run_greeter_client.sh 没问题的话,在服务端会显示: $ 2019/10/18 16:03:50 Received: world
参考连接:
https://grpc.io/docs/quickstart/php/
go安装grpc连接php-fpm