beauty-framework/grpc
最新稳定版本:1.0.1
Composer 安装命令:
composer require beauty-framework/grpc
包简介
Beauty gRPC
README 文档
README
Support for gRPC services in the Beauty Framework, powered by RoadRunner GRPC plugin.
✨ Installation
Via composer:
make composer require beauty-framework/grpc
# or manually, if you don't use docker
composer require beauty-framework/grpc
Run the following command:
make beauty grpc:install
# or manually
./beauty grpc:install
make composer du
# or manually
composer dump-autoload
This will:
- 📁 Create the
generated/directory for compiled gRPC PHP classes - 🧪 Add
"GRPC\\": "generated/"tocomposer.jsonautoload - 📝 Copy the
grpc-worker.phpstub into theworkers/directory - 🔌 Run
vendor/bin/rr download-protoc-binaryto install theprotocbinary
Add command to makefile:
grpcgen: docker-compose exec -u www-data $(APP_CONTAINER) protoc --plugin=protoc-gen-php-grpc \ --php_out=./generated \ --php-grpc_out=./generated \ $(filter-out $@,$(MAKECMDGOALS))
and to PHONY block append this command name: grpcgen
🛠 Usage
1. Compile your .proto files:
make grpcgen proto/helloworld.proto
To compile multiple:
make grpcgen proto/*.proto
Alternatively, use manually:
docker-compose exec -u www-data app protoc \
--plugin=protoc-gen-php-grpc \
--php_out=./generated \
--php-grpc_out=./generated \
proto/helloworld.proto
2. Configure .rr.yaml
grpc: listen: tcp://0.0.0.0:51015 pool: command: "php workers/grpc-worker.php" proto: - "proto/helloworld.proto"
3. Start the server
Add new ports in docker-compose.yml in app service:
services: app: ports: - "51015:51015"
make stop && make up # or manually ./vendor/bin/rr serve
This will start the gRPC server at 127.0.0.1:9001.
🔧 Example Service
namespace App\Controllers\GRPC; use GRPC\Greeter\GreeterInterface; use GRPC\Greeter\HelloRequest; use GRPC\Greeter\HelloReply; use Beauty\GRPC\GrpcService; use Spiral\RoadRunner\GRPC\ContextInterface; #[GrpcService(GreeterInterface::class)] class Greeter implements GreeterInterface { public function SayHello(ContextInterface $ctx, HelloRequest $in): HelloReply { return new HelloReply([ 'message' => 'Hello ' . $in->getName(), ]); } }
📎 Documentation
Official RoadRunner gRPC plugin docs: 🔗 https://docs.roadrunner.dev/docs/plugins/grpc
🛋 Notes
- Services are automatically discovered from
app/Controllers/GRPC/**/*.phpvia#[GrpcService(...)] - All generated classes are stored in
generated/ - Re-run
make grpcgenwhenever you change.protofiles
❤️ Stack
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-15