Download the PHP package mix/grpc-skeleton without Composer
On this page you can find all versions of the php package mix/grpc-skeleton. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mix/grpc-skeleton
More information about mix/grpc-skeleton
Files in mix/grpc-skeleton
Package grpc-skeleton
Short Description gRPC development skeleton
License Apache-2.0
Homepage https://openmix.org/mix-php
Informations about the package grpc-skeleton
gRPC development skeleton
帮助你快速搭建 gRPC 项目骨架,并指导你如何使用该骨架的细节,骨架默认开启了 SQL、Redis 日志,压测前请先关闭 .env
的 APP_DEBUG
安装
需要先安装 Swoole
- Swoole >= 4.4.4: https://wiki.swoole.com/#/environment
- 需要开启
--enable-http2
快速开始
启动 Swoole 多进程服务
启动 Swoole 协程服务
执行脚本
composer run-script
命令中的--timeout=0
参数是防止 composer 执行超时composer.json
定义了命令执行脚本,对应上面的执行命令
当然也可以直接下面这样启动,效果是一样的,但是 scripts
能帮你记录到底有哪些可用的命令,同时在IDE中调试更加方便。
编写一个 gRPC 接口
首先修改根目录 .env
文件的数据库信息
然后在 proto
目录创建 greeter.proto
文件,并根据 使用说明 将 .proto 文件生成为 PHP 代码
然后创建一个新的服务 src/Service/Say.php
Say
类实现了代码生成器生成的Php\Micro\Grpc\Greeter\SayInterface
接口
在 src/Grpc.php
中将服务注册到服务器
重新启动服务器后方可测试新开发的接口
实际开发中使用 PhpStorm 的 Run 功能,只需要点击一下重启按钮即可
如何使用 gRPC 客户端
使用容器中的对象
容器采用了一个简单的单例模式,你可以修改为更加适合自己的方式。
-
数据库:mix/database
-
Redis:mix/redis
- 配置:hassankhan/config
部署
线上部署启动时,修改 shell/server.sh
脚本中的绝对路径和参数
启动管理
gRPC 通常都是内部使用,使用内网 SLB
代理到服务器IP或者直接使用 IP:PORT 调用
License
Apache License Version 2.0, http://www.apache.org/licenses/
All versions of grpc-skeleton with dependencies
mix/vega Version ~3.0.0
mix/grpc Version ~3.0.0
mix/cli Version ~3.0.0
mix/database Version ~3.0.0
mix/redis Version ~3.0.0
vlucas/phpdotenv Version ^5.3
hassankhan/config Version ^3.0
monolog/monolog Version ^3.1