beauty-framework / grpc
Beauty gRPC
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/beauty-framework/grpc
Requires
- php: >=8.1
- beauty-framework/cli: ^1.0
- spiral/roadrunner-cli: ^2.7
- spiral/roadrunner-grpc: ^3.5
- symfony/finder: ^7.3
This package is not auto-updated.
Last update: 2025-10-20 14:27:11 UTC
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