PHP code example of roadrunner / grpc

1. Go to this page and download the library: Download roadrunner/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/ */

    

roadrunner / grpc example snippets


use Service\EchoInterface;
use Service\Message;
use Spiral\RoadRunner\GRPC\ContextInterface;

final class EchoService implements EchoInterface
{
    public function Ping(ContextInterface $ctx, Message $in): Message
    {
        return (new Message())->setMsg(\date('Y-m-d H:i:s') . ': PONG');
    }
}

use Service\EchoInterface;
use Spiral\RoadRunner\GRPC\Invoker;
use Spiral\RoadRunner\GRPC\Server;
use Spiral\RoadRunner\Worker;

rface::class, new EchoService());

$server->serve(Worker::create());
yaml
version: "3"

server:
  command: "php worker.php"

grpc:
  listen: "tcp://127.0.0.1:9001"
  proto: ["service.proto"]
bash
protoc --php_out=src --php-grpc_out=src service.proto