Skip to content
roadrunner-phpPublic

About

🔌 RoadRunner GRPC SDK

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

66 stars

Watchers

3 watching

Forks

Repository files navigation

RoadRunner

High-performance gRPC server for PHP applications

Documentation Sponsor

Psalm Level Type Coverage Codecov Mutation testing badge


RoadRunner GRPC is the PHP side of the RoadRunner gRPC plugin. It runs your PHP gRPC services inside RoadRunner workers, so PHP and Golang services can live within one application.

Get Started

Installation

composer require roadrunner/grpc

PHP Latest Version on Packagist License Total Downloads

Configuration

Enable the grpc plugin in .rr.yaml and point it at your .proto files:

version: "3"

server:
  command: "php worker.php"

grpc:
  listen: "tcp://127.0.0.1:9001"
  proto: ["service.proto"]

All available options are described in the plugin documentation.

Generating Service Code

Service interfaces and messages are generated from .proto files with protoc and the protoc-gen-php-grpc plugin, which can be downloaded from the RoadRunner releases page:

protoc --php_out=src --php-grpc_out=src service.proto

Writing a Service

Implement the generated interface:

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');
    }
}

Running the Worker

Register the service in worker.php and start serving requests:

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

require __DIR__ . '/vendor/autoload.php';

$server = new Server(new Invoker(), [
    'debug' => false, // optional (default: false)
]);

$server->registerService(EchoInterface::class, new EchoService());

$server->serve(Worker::create());

Then run rr serve. A complete echo service with a client is in the example directory.

Features

  • native Golang GRPC implementation compliant
  • minimal configuration, plug-and-play model
  • very fast, low footprint proxy
  • simple TLS configuration
  • debug tools included
  • Prometheus metrics
  • middleware and server customization support
  • code generation using the protoc-gen-php-grpc plugin for protoc (download the version matching your RoadRunner, e.g. protoc-gen-php-grpc-3.0.0-*, from the roadrunner releases page)
  • transport, message, worker error management
  • response error codes over php exceptions
  • works on Windows
try Spiral Framework

About

🔌 RoadRunner GRPC SDK

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

66 stars

Watchers

3 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages