1.0.1 2025-06-15 14:37 UTC

This package is not auto-updated.

Last update: 2025-06-15 20:55:14 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/" to composer.json autoload
  • ๐Ÿ“ Copy the grpc-worker.php stub into the workers/ directory
  • ๐Ÿ”Œ Run vendor/bin/rr download-protoc-binary to install the protoc binary

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/**/*.php via #[GrpcService(...)]
  • All generated classes are stored in generated/
  • Re-run make grpcgen whenever you change .proto files

โค๏ธ Stack