PHP code example of beauty-framework / grpc

1. Go to this page and download the library: Download beauty-framework/grpc library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

beauty-framework / grpc example snippets


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(),
        ]);
    }
}
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))
bash
docker-compose exec -u www-data app protoc \
  --plugin=protoc-gen-php-grpc \
  --php_out=./generated \
  --php-grpc_out=./generated \
  proto/helloworld.proto
yaml
grpc:
  listen: tcp://0.0.0.0:51015
  pool:
    command: "php workers/grpc-worker.php"
  proto:
    - "proto/helloworld.proto"