Home > Article > Backend Development > One article explains in detail the implementation of grpc server through php+roadrunner
This article brings you relevant knowledge about PHP. It mainly introduces how to implement grpc server through php roadrunner. Friends who are interested can take a look below. I hope it will be helpful to everyone.
Warehouse address:
https://github.com/zhonghaibin/php-grpc-serve
Download source code:
git clone https://github.com/zhonghaibin/php-grpc-serve
The php version I use: php 8.2
Installation command line input
composer install
Get the rr.exe executable file command line input
./vendor/bin/rr get-binary
Start the service./rr.exe serve
I am using ApiPost to support grpc testing
打开apipost客户端,新建grpc,选择导入proto 选择项目目录的 grpc/protos/base/hello-world.proto 文件##grpc reference document:
roadrunner.dev/docs/plugins-grpc/2...
protoc construction steps1 Create Protobuf hello according to your own needs -world.proto file2 Generate php class file through hello-world.proto这里需要下载两个可执行文件把 hello-world.proto 生成 php文件, 因为我用的是win10: 所以下载的是 protoc.exe 和 protoc-gen-php-grpc.exe 这两个文件我放在项目里 protoc-22.3-win64 文件夹里面,如果你和我环境一样直接用我下载好的即可,其他平台请自行下载 下载地址:https://github.com/roadrunner-server/roadrunner/releases 生成php文件命令如下:./protoc.exe --plugin=protoc-gen-php-grpc.exe --php_out=./ --php-grpc_out=./ hello-world.proto 这里会在当前目录下生成两个文件夹:GPBMetadata 和 Services 把生成好的文件夹复制到 项目目录的 grpc/generated 目录下
root ├─app │ ├─console │ ├─services │ │ ├─Task //异步任务│ │ └─HelloService.php //写自己的业务│ └─support ├─config ├─grpc │ ├─generated //使用protoc自动构建的类均存在这│ │ ├─Services //服务统一命名空间│ │ └─GPBMetadata //GRPC生成的元数据├ └─protos //所有proto存在这里Recommended learning: "
PHP Video Tutorial"
The above is the detailed content of One article explains in detail the implementation of grpc server through php+roadrunner. For more information, please follow other related articles on the PHP Chinese website!