百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

laravel-bridge

> 后端框架
开源

为 RoadRunner 提供完整的 Laravel 集成,支持 HTTP、作业、gRPC 和 Temporal 插件 – 远超出 Octane 的能力

507 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

为 RoadRunner 提供完整的 Laravel 集成,支持 HTTP、作业、gRPC 和 Temporal 插件 – 远超出 Octane 的能力

[RoadRunner][roadrunner] ⇆ [Laravel][laravel] bridge

[![Version][badge_packagist_version]][link_packagist] [![Version][badge_php_version]][link_packagist] [![License][badge_license]][link_license]

Easy way for connecting [RoadRunner][roadrunner] and [Laravel][laravel] applications (community integration).

Why Use This Package?

This package provides complete Laravel integration with RoadRunner, offering:

  • Support for HTTP and other RoadRunner plugins like gRPC, Queue, KeyValue, and more.
  • Temporal integration
  • Full RoadRunner configuration control
  • PSR-3 compatible logging with RoadRunner integration

[!TIP] [There is an article][rr-plugins-article] that explains all the RoadRunner plugins.

Table of Contents

  • Get Started
    • Installation
    • Configuration
    • Starting the Server
  • How It Works
  • Supported Plugins
    • HTTP Plugin
    • Jobs (Queue) Plugin
    • gRPC Plugin
    • gRPC Client
    • Temporal
  • Logging
  • Custom Workers
  • Support
  • License

Get Started

Installation

First, install the Laravel Bridge package via Composer:

bash
composer require roadrunner-php/laravel-bridge

Publish the configuration file:

bash
php artisan vendor:publish --provider='Spiral\RoadRunnerLaravel\ServiceProvider' --tag=config

Download and install RoadRunner binary using DLoad:

bash
./vendor/bin/dload get rr

Configuration

Create a .rr.yaml configuration file in your project root:

yaml
version: '3'
rpc:
  listen: 'tcp://127.0.0.1:6001'

server:
  command: 'php vendor/bin/rr-worker start'

http:
  address: 0.0.0.0:8080
  middleware: [ "static", "headers", "gzip" ]
  pool:
    #max_jobs: 64 # feel free to change this
    supervisor:
      exec_ttl: 60s
  headers:
    response:
      X-Powered-By: "RoadRunner"
  static:
    dir: "public"
    forbid: [ ".php" ]

Starting the Server

Start the RoadRunner server with:

bash
./rr serve

How It Works

RoadRunner creates a worker pool by executing the command specified in the server configuration:

yaml
server:
  command: 'php vendor/bin/rr-worker start'

When RoadRunner creates a worker pool for a specific plugin, it sets the RR_MODE environment variable to indicate which plugin is being used. The Laravel Bridge checks this variable to determine which Worker class should handle the request based on your configuration.

The selected worker then listens for requests from the RoadRunner server and handles them using the [Octane][octane] worker, which clears the application state after each task (request, command, etc.).

Supported Plugins

HTTP Plugin

The HTTP plugin enables serving HTTP requests with your Laravel application through RoadRunner.

Configuration

Ensure your .rr.yaml has the HTTP section configured:

yaml
http:
  address: 0.0.0.0:8080
  middleware: [ "static", "headers", "gzip" ]
  pool:
    max_jobs: 64
  static:
    dir: "public"
    forbid: [ ".php" ]

[!TIP] Read more about the HTTP plugin in the [RoadRunner documentation][roadrunner-docs-http].

Jobs (Queue) Plugin

The Queue plugin allows you to use RoadRunner as a queue driver for Laravel without additional services like Redis or a database.

Configuration

First, add the Queue Service Provider in config/app.php:

php
'providers' => [
    // ... other providers
    Spiral\RoadRunnerLaravel\Queue\QueueServiceProvider::class,
],

Then, configure a new connection in config/queue.php:

php
'connections' => [
    // ... other connections
   'roadrunner' => [
      'driver' => 'roadrunner',
      'queue' => env('RR_QUEUE', 'default'),
      'retry_after' => (int) env('RR_QUEUE_RETRY_AFTER', 90),
      'after_commit' => false,
   ],
],

Update your .rr.yaml file to include the Jobs section:

yaml
jobs:
  pool:
    num_workers: 4
  pipelines:
    default:
      driver: memory
      config: { }

Set the QUEUE_CONNECTION environment variable in your .env file:

dotenv
QUEUE_CONNECTION=roadrunner

That's it! You can now dispatch jobs to the RoadRunner queue without any additional services like Redis or Database.

[!TIP] Read more about the Jobs plugin in the [RoadRunner documentation][roadrunner-docs-jobs].

gRPC Plugin

The gRPC plugin enables serving gRPC services with your Laravel application.

Configuration

Configure gRPC in your .rr.yaml:

yaml
grpc:
  listen: 'tcp://0.0.0.0:9001'
  proto:
    - "proto/service.proto"

Then, add your gRPC services to config/roadrunner.php:

php
return [
    // ... other configuration
    'grpc' => [
        'services' => [
            \App\GRPC\EchoServiceInterface::class => \App\GRPC\EchoService::class,

            // Service with specific interceptors
            \App\GRPC\UserServiceInterface::class => [
                'service' => \App\GRPC\UserService::class,
                'interceptors' => [
                    \App\GRPC\Interceptors\ValidationInterceptor::class,
                    \App\GRPC\Interceptors\CacheInterceptor::class,
                ],
            ],
        ]
    ],
];

gRPC Server Interceptors

Create your interceptor by implementing Spiral\Interceptors\InterceptorInterface:

php
getTarget()->getPath();
        \Log::info("gRPC call: {$method}");

        $response = $handler->handle($context);

        \Log::info("gRPC response: {$method}");

        return $response;
    }
}
Interceptors Configuration

Configure interceptors in config/roadrunner.php. You can use global interceptors that apply to all services, service-specific interceptors, or both:

…
Using Attribute-Based Interceptors

For additional flexibility and convenience, you can use the AttributesInterceptor to apply interceptors via PHP attributes directly on your service classes and methods. This allows you to define which interceptors should be applied at a more granular level.

To enable attribute-based interceptors, add the AttributesInterceptor to your global interceptors list:

php
'interceptors' => [
    // ... other global interceptors before
    \Spiral\RoadRunnerLaravel\Common\Interceptor\AttributesInterceptor::class,
    // ... other global interceptors after
],

Then, create interceptors that can be used as attributes:

php
checkRole($this->role)) {
            throw new \RuntimeException('Access denied');
        }

        return $handler->handle($context);
    }
}

Apply interceptors to your gRPC service classes or methods:

php
 [
        // ... server config
        'clients' => [
            'services' => [
                [
                    'connection' => '127.0.0.1:9001', // gRPC server address
                    'interfaces' => [
                        \App\Grpc\EchoServiceInterface::class,
                    ],
                    // 'tls' => [ ... ] // Optional TLS configuration
                ],
            ],
            // 'interceptors' => [ ... ] // Optional interceptors
        ],
    ],
];
Using the gRPC Client in Laravel

You can inject Spiral\Grpc\Client\ServiceClientProvider into your services or controllers to obtain a gRPC client instance:

php
use Spiral\Grpc\Client\ServiceClientProvider;
use App\Grpc\EchoServiceInterface;
use App\Grpc\EchoRequest;

class GrpcController extends Controller
{
    public function callService(ServiceClientProvider $provider)
    {
        /** @var EchoServiceInterface $client */
        $client = $provider->get(EchoServiceInterface::class);

        $request = new EchoRequest();
        $request->setMessage('Hello from client!');

        $response = $client->Echo($request);

        return $response->getMessage();
    }
}

Note:

  • Make sure you have generated the PHP classes from your .proto files (using protoc).
  • The connection and interfaces must match the service you want to call.
  • You can configure multiple gRPC client services as needed.

Temporal

Temporal is a workflow engine that enables orchestration of microservices and provides sophisticated workflow mechanisms.

Configuration

First, configure Temporal in your .rr.yaml:

yaml
temporal:
  address: 127.0.0.1:7233
  activities:
    num_workers: 10

Then, configure your workflows and activities in config/roadrunner.php:

php
return [
    // ... other configuration
    'temporal' => [
        'address' => env('TEMPORAL_ADDRESS', '127.0.0.1:7233'),
        'namespace' => 'default',
        'declarations' => [
            \App\Temporal\Workflows\MyWorkflow::class,
            \App\Temporal\Activities\MyActivity::class,
        ],
    ],
];

Download Temporal binary for development:

bash
./vendor/bin/dload get temporal

Start the Temporal dev server:

bash
./temporal server start-dev --log-level error --color always

Useful Links

  • PHP SDK on GitHub
  • PHP SDK docs
  • Code samples
  • Taxi service sample

Logging

The RoadRunner PSR Logger provides PSR-3 compatible logging with RoadRunner integration. The logger uses RPC calls to send logs to RoadRunner's centralized logging system, providing proper log level control and structured context support.

Usage

The RoadRunner PSR Logger is available throughout your application via dependency injection:

Dependency Injection (Recommended)

php
use Psr\Log\LoggerInterface;

class YourService
{
    public function __construct(
        private LoggerInterface $logger
    ) {}

    public function doSomething()
    {
        $this->logger->info('Operation started');

        try {
            // Your logic here
            $this->logger->info('Operation completed');
        } catch (\Exception $e) {
            $this->logger->error('Operation failed', [
                'exception' => $e->getMessage(),
                'trace' => $e->getTraceAsString()
            ]);
        }
    }
}

Service Container Resolution

php
// Get logger from container
$logger = app(LoggerInterface::class);
// Or using the alias
$logger = app('roadrunner.logger');

$logger->info('Message', ['context' => 'data']);

Useful Links

  • RoadRunner PSR Logger

Custom Workers

The RoadRunner Laravel Bridge comes with several predefined workers for common plugins, but you can easily create your own custom workers for any RoadRunner plugin. This section explains how to create and register custom workers in your application.

Understanding Workers

Workers are responsible for handling requests from the RoadRunner server and processing them in your Laravel application. The predefined workers are configured in the config/roadrunner.php file:

php
return [
    // ... other configuration options ...

    'workers' => [
        Mode::MODE_HTTP => HttpWorker::class,
        Mode::MODE_JOBS => QueueWorker::class,
        Mode::MODE_GRPC => GrpcWorker::class,
        Mode::MODE_TEMPORAL => TemporalWorker::class,
    ],
];

Creating Custom Workers

To create a custom worker, you need to implement the Spiral\RoadRunnerLaravel\WorkerInterface. This interface has a single method, start(), which is called when the worker is started by the RoadRunner server:

php
namespace App\Workers;

use Spiral\RoadRunnerLaravel\WorkerInterface;
use Spiral\RoadRunnerLaravel\WorkerOptionsInterface;

class CustomWorker implements WorkerInterface
{
    public function start(WorkerOptionsInterface $options): void
    {
        // Your worker implementation goes here

Issues· 5 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPlaravelpackagephproadrunner

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架