• Stars
    star
    343
  • Rank 119,560 (Top 3 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 4 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸŒ‰ RoadRunner ⇆ Laravel bridge πŸ‡ΊπŸ‡¦β€οΈ

logo

RoadRunner ⇆ Laravel bridge

Version Version Build Status Coverage Downloads count Chat License

Easy way for connecting RoadRunner and Laravel applications (community integration).

πŸ‹ If you want to see an example of a laravel application in a docker container with RoadRunner as a web server - take a look at this repository.

Installation

Make sure that RR binary file already installed on your system (or docker image). Require this package with composer using next command:

$ composer require spiral/roadrunner-laravel

Installed composer is required (how to install composer).

After that you can "publish" package configuration file (./config/roadrunner.php) using next command:

$ php ./artisan vendor:publish --provider='Spiral\RoadRunnerLaravel\ServiceProvider' --tag=config

Important: despite the fact that worker allows you to refresh application instance on each HTTP request (if worker started with option --refresh-app, eg.: php ./vendor/bin/rr-worker start --refresh-app), we strongly recommend avoiding this for performance reasons. Large applications can be hard to integrate with RoadRunner (you must decide which of service providers must be reloaded on each request, avoid "static optimization" in some cases), but it's worth it.

Upgrading guide

v4.x β†’ v5.x

  • Update current package in your application:
    • composer remove spiral/roadrunner-laravel
    • composer require spiral/roadrunner-laravel "^5.0"
  • Update package configuration file (roadrunner.php; take a look for actual example in current repository)

v3.x β†’ v4.x

  • Update current package in your application:
    • composer remove spiral/roadrunner-laravel
    • composer require spiral/roadrunner-laravel "^4.0"
  • Update your .rr.yaml config (take a look for sample here) - a lot of options was changed
    • Optionally change relay to socket or TCP port:
      server:
        command: "php ./vendor/bin/rr-worker start --relay-dsn unix:///var/run/rr-relay.sock"
        relay: "unix:///var/run/rr-relay.sock"
  • Update RR binary file (using roadrunner-cli or download from binary releases page) up to v2.x
  • Update RoadRunner starting (rr serve ...) flags - -v and -d must be not used anymore
  • In your application code replace Spiral\RoadRunner\PSR7Client with Spiral\RoadRunner\Http\PSR7Worker

Usage

After package installation you can use provided "binary" file as RoadRunner worker: ./vendor/bin/rr-worker. This worker allows you to interact with incoming requests and outgoing responses using laravel events system. Event contains:

Event classname Application object HTTP server request HTTP request HTTP response Exception
BeforeLoopStartedEvent βœ”
BeforeLoopIterationEvent βœ” βœ”
BeforeRequestHandlingEvent βœ” βœ”
AfterRequestHandlingEvent βœ” βœ” βœ”
AfterLoopIterationEvent βœ” βœ” βœ”
AfterLoopStoppedEvent βœ”
LoopErrorOccurredEvent βœ” βœ” βœ”

Simple .rr.yaml config example (full example can be found here):

For windows path must be full (eg.: php vendor/spiral/roadrunner-laravel/bin/rr-worker start)

version: "2.7"

server:
  command: "php ./vendor/bin/rr-worker start --relay-dsn unix:///var/run/rr-relay.sock"
  relay: "unix:///var/run/rr-relay.sock"

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"]

Socket or TCP port relay usage is strongly recommended for avoiding problems with dd(), dump(), echo() and other similar functions, that sends data to the IO pipes.

Roadrunner server starting:

$ rr serve -c ./.rr.yaml

Listeners

This package provides event listeners for resetting application state without full application reload (like cookies, HTTP request, application instance, service-providers and other). Some of them already declared in configuration file, but you can declare own without any limitations.

Helpers

This package provides the following helpers:

Name Description
\rr\dump(...) Dump passed values (dumped result will be available in the HTTP response)
\rr\dd(...) Dump passed values and stop the execution
\rr\worker() Easy access to the RoadRunner PSR worker instance

Known issues

Performance degradation

...when file driver is set for your sessions. Please, use redis (or something similar) driver instead (related issue). This package or/and RoadRunner has nothing to do with it, but since this is a fairly common issue - it is described here.

Controller constructors

You should avoid to use HTTP controller constructors (created or resolved instances in a constructor can be shared between different requests). Use dependencies resolving in a controller methods instead.

Bad:

<?php

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    /**
     * The user repository instance.
     */
    protected $users;

    /**
     * @var Request
     */
    protected $request;

    /**
     * @param UserRepository $users
     * @param Request        $request
     */
    public function __construct(UserRepository $users, Request $request)
    {
        $this->users   = $users;
        $this->request = $request;
    }

    /**
     * @return Response
     */
    public function store(): Response
    {
        $user = $this->users->getById($this->request->id);

        // ...
    }
}

Good:

<?php

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    /**
     * @param  Request        $request
     * @param  UserRepository $users
     *
     * @return Response
     */
    public function store(Request $request, UserRepository $users): Response
    {
        $user = $users->getById($request->id);

        // ...
    }
}

Middleware constructors

You should never to use middleware constructor for session, session.store, auth or auth Guard instances resolving and storing in properties (for example). Use method-injection or access them through Request instance.

Bad:

<?php

use Illuminate\Http\Request;
use Illuminate\Session\Store;

class Middleware
{
    /**
     * @var Store
     */
    protected $session;

    /**
     * @param Store $session
     */
    public function __construct(Store $session)
    {
        $this->session = $session;
    }

    /**
     * Handle an incoming request.
     *
     * @param Request  $request
     * @param \Closure $next
     *
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        $name = $this->session->getName();

        // ...

        return $next($request);
    }
}

Good:

<?php

use Illuminate\Http\Request;

class Middleware
{
    /**
     * Handle an incoming request.
     *
     * @param Request  $request
     * @param \Closure $next
     *
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        $name = $request->session()->getName();
        // $name = resolve('session')->getName();

        // ...

        return $next($request);
    }
}

Testing

For package testing we use phpunit framework and docker-ce + docker-compose as develop environment. So, just write into your terminal after repository cloning:

$ make build
$ make latest # or 'make lowest'
$ make test

Changes log

Release date Commits since latest release

Changes log can be found here.

Support

Issues Issues

If you find any package errors, please, make an issue in a current repository.

License

MIT License (MIT). Please see LICENSE for more information. Maintained by tarampampam and Spiral Scout.

More Repositories

1

framework

High-Performance PHP Framework
PHP
1,693
star
2

app

Spiral Framework Skeleton HTTP Application: Queue, Console, Cycle ORM
PHP
189
star
3

ticket-booking

This is an example project based on the Spiral Framework and GRPC microservices.
PHP
58
star
4

goridge-php

PHP Goridge Protocol implementation
PHP
50
star
5

app-keeper

Skeleton Application on Spiral Framework: Keeper Admin Panel
Hack
46
star
6

json-schema-generator

Provides the ability to generate JSON schemas from Data Transfer Object (DTO) classes
PHP
41
star
7

docs

Spiral Framework and Components Documentation
41
star
8

app-grpc

Spiral Framework Skeleton GRPC Application: Queue, Console, ORM
PHP
34
star
9

storage

[READ ONLY] Object Storage API: Amazon, FTP, SFTP, Filesystem, GridFS. Subtree split of the Spiral Storage component (see spiral/framework)
PHP
28
star
10

shopify-starter-kit

Starter theme and environment for the largest Shopify stores.
Liquid
24
star
11

roadrunner-grpc

πŸ”Œ RoadRunner GRPC SDK
PHP
24
star
12

attributes

PHP Attributes Reader. Subtree split of the Spiral Attributes component (see spiral/framework)
PHP
22
star
13

cycle-bridge

πŸŒ‰ Cycle ORM v2 bridge to Spiral Framework
PHP
17
star
14

roadrunner-jobs

πŸ”Œ RoadRunner Jobs (Queue) SDK
PHP
16
star
15

tokenizer

[READ ONLY] Locate available classes by parent, interface or trait. Subtree split of the Spiral Tokenizer component (see spiral/framework)
PHP
15
star
16

roadrunner-cli

RoadRunner binary download utility.
PHP
14
star
17

stempler

[READ ONLY] Server-side html-component compiler and template engine. Subtree split of the Spiral Stempler component (see spiral/framework)
PHP
14
star
18

temporal-bridge

πŸŒ‰ Temporal integration package for Spiral Framework
PHP
13
star
19

roadrunner-broadcast

πŸ”Œ RoadRunner Broadcast SDK
PHP
12
star
20

roadrunner-http

PSR7 Worker Client for RoadRunner 2.0 application server.
PHP
12
star
21

core

[READ ONLY] IoC container, IoC scopes, factory, memory, configuration interfaces. Subtree split of the Spiral Core component (see spiral/framework)
PHP
12
star
22

roadrunner-bridge

πŸŒ‰ RoadRunner bridge to Spiral Framework
PHP
11
star
23

demo

Spiral Demo Application
PHP
11
star
24

roadrunner-worker

Base PHP worker for RoadRunner server.
PHP
11
star
25

app-cli

Spiral Framework Skeleton CLI Application
PHP
11
star
26

keeper

Data and UI framework for portals with RBAC security model
PHP
10
star
27

logger

[READ ONLY] LogFactory and global log listeners. Subtree split of the Spiral Logger component (see spiral/framework)
PHP
10
star
28

toolkit

Dynamic forms and Grids toolkit
TypeScript
8
star
29

roadrunner-services

πŸ”Œ RoadRunner Services SDK
PHP
8
star
30

testing

Spiral Framework testing SDK
PHP
8
star
31

roadrunner-tcp

TCP Worker Client for RoadRunner 2.0 application server
PHP
8
star
32

profiler

Spiral: Profiler and Debug Panel
PHP
7
star
33

dumper

Colorful variable dumper: HTML, logs and CLI support. Subtree split of the Spiral Dumper component (see spiral/framework)
PHP
7
star
34

data-grid

Data Grid and specification builder. Subtree split of the Spiral Data Grid component (see spiral/framework)
PHP
6
star
35

pagination

[READ ONLY] Common pagination interfaces. Subtree split of the Spiral Pagination component (see spiral/framework)
PHP
6
star
36

otel-bridge

OpenTelemetry bridge for Spiral Framework
PHP
5
star
37

sentry-bridge

Spiral: Sentry Snapshot Bridge
PHP
5
star
38

reactor

[READ ONLY] Code Scaffolding using declarative OOP wrappers. Subtree split of the Spiral Reactor component (see spiral/framework)
PHP
5
star
39

roadrunner-kv

πŸ”Œ RoadRunner Key-Value storage SDK
PHP
5
star
40

auth

[READ ONLY] Basic authentication module with authorizers and firewalls. Subtree split of the Spiral Auth component (see spiral/framework)
PHP
5
star
41

files

[READ ONLY] File Toolkit: atomic file manager, virtual file streams. Subtree split of the Spiral Files component (see spiral/framework)
PHP
5
star
42

router

[READ ONLY] Routes, RESTFul, URI generation, Adaptive Patterns. Subtree split of the Spiral Router component (see spiral/framework)
PHP
5
star
43

cookies

[READ ONLY] Secure Cookie middleware. Subtree split of the Spiral Cookies component (see spiral/framework)
PHP
4
star
44

exceptions

[READ ONLY] Universal Exception Handler: console, web exception handlers, code highlights, snapshotting support. Subtree split of the Spiral Exceptions component (see spiral/framework)
PHP
4
star
45

validator

The component provides an array-based DSL to construct complex validation chains.
PHP
4
star
46

composer-publish-plugin

Automatically publish package files using composer declaration
PHP
4
star
47

validation

[READ ONLY] Nested Validation, Checkers, Conditional Validation, Multiple Rule syntaxes. Subtree split of the Spiral Validation component (see spiral/framework)
PHP
4
star
48

models

[READ ONLY] Set of common data wrappers with field mutators, strict data schemas and reflection capabilities. Subtree split of the Spiral Models component (see spiral/framework)
PHP
4
star
49

http

[READ ONLY] PSR-15 HTTP Request pipeline. Subtree split of the Spiral HTTP component (see spiral/framework)
PHP
4
star
50

prototype

[READ ONLY] Automatic dependency injection using AST modifications. Subtree split of the Spiral Prototype component (see spiral/framework)
PHP
4
star
51

scaffolder

[READ ONLY] Set of commands used to scaffold parts of application. Subtree split of the Spiral Scaffolder component (see spiral/framework)
PHP
3
star
52

security

[READ ONLY] RBAC security layer based on NIST definition, role/rule/permission associations, bulletproof. Subtree split of the Spiral Security component (see spiral/framework)
PHP
3
star
53

filters-bridge

Bridge for Spiral framework 2.x filters for Spiral Framework 3.0
PHP
3
star
54

roadrunner-metrics

πŸ”Œ RoadRunner Metrics SDK
PHP
3
star
55

code-style

Code-Style sniffer and fixer rules and CLI command
PHP
3
star
56

debug

[READ ONLY] Debug Toolkit. Subtree split of the Spiral Debug component (see spiral/framework)
PHP
3
star
57

boot

[READ ONLY] Spiral Boot Core: Environment Bootloader, Dispatcher, Memory. Subtree split of the Spiral Boot component (see spiral/framework)
PHP
3
star
58

console

[READ ONLY] Console Core, Auto-Discovery, Command Sequencing. Subtree split of the Spiral Console component (see spiral/framework)
PHP
3
star
59

encrypter

[READ ONLY] Encryption component. Subtree split of the Spiral Encrypter component (see spiral/framework)
PHP
3
star
60

snapshots

[READ ONLY] Snapshots: Exception handling interfaces. Subtree split of the Spiral Snapchots component (see spiral/framework)
PHP
3
star
61

monolog-bridge

[READ ONLY] Spiral Framework: Monolog Adapter. Subtree split of the Spiral Monolog Bridge component (see spiral/framework)
PHP
3
star
62

annotated-routes

[READ ONLY] Enables Route annotation in application controllers. Subtree split of the Spiral Annotated Routes component (see spiral/framework)
PHP
3
star
63

distribution

[READ ONLY] Content distribution over CDN.
PHP
3
star
64

sendit

Email builder and sending pipeline.
PHP
3
star
65

views

[READ ONLY] View Manager and Rendering Engine selector. Subtree split of the Spiral Views component (see spiral/framework)
PHP
3
star
66

stempler-bridge

[READ ONLY] Spiral Framework: Stempler adapter. Subtree split of the Spiral Stempler Bridge component (see spiral/framework)
PHP
3
star
67

hmvc

[READ ONLY] HMVC Core and Controllers. Subtree split of the Spiral HMVC component (see spiral/framework)
PHP
3
star
68

dotenv-bridge

[READ ONLY] DotEnv Loader for Spiral Framework. Subtree split of the Spiral DotEnv component (see spiral/framework)
PHP
2
star
69

marshaller

PHP
2
star
70

config

[READ ONLY] Config injector and configuration mutator. Subtree split of the Spiral Config component (see spiral/framework)
PHP
2
star
71

filters

[READ ONLY] Deep Structural Validation, Data Mapper, Inheritance. Subtree split of the Spiral Filters component (see spiral/framework)
PHP
2
star
72

session

[READ ONLY] Secure sessions over native PHP handlers. Subtree split of the Spiral Session component (see spiral/framework)
PHP
2
star
73

roadmap

2
star
74

sapi-bridge

Spiral Framework SAPI bridge
PHP
2
star
75

streams

[READ ONLY] PSR-7 Stream Wrappers. Subtree split of the Spiral Stream component (see spiral/framework)
PHP
2
star
76

translator

[READ ONLY] Translator, Static Analysis and Auto-Indexation. Subtree split of the Spiral Translator component (see spiral/framework)
PHP
2
star
77

simple-chat

A real-time demo chat application using the Spiral Framework, RoadRunner, and Centrifugo with authentication and bidirectional communication.
JavaScript
2
star
78

data-grid-bridge

Data-Grid adapter for spiral framework. Subtree split of the Spiral Attributes component (see spiral/framework)
PHP
2
star
79

grpc-skeleton

A template of GRPC package with shared interfaces and clients for microservices.
PHP
1
star
80

temporal-interceptors

PHP
1
star
81

docker-php-grpc

Dockerfile
1
star
82

csrf

[READ ONLY] CSRF Middleware. Subtree split of the Spiral Csrf component (see spiral/framework)
PHP
1
star
83

telemetry

Generates telemetry traces to help you analyze your software’s performance and behavior.
PHP
1
star
84

events

Spiral Framework: PSR-14 Event Dispatcher
PHP
1
star
85

serializer

Spiral Framework component for serializing and deserializing data structure
PHP
1
star
86

lock-bridge

πŸ”Œ Integration package for the RoadRunner Lock package
PHP
1
star
87

auth-http

[READ ONLY] Auth Middleware and HTTP Token transports. Subtree split of the Spiral AuthHttp component (see spiral/framework)
PHP
1
star
88

marshaller-bridge

Marshaller bridge for Spiral Framework
PHP
1
star
89

queue

[READ ONLY] RoadRunner: Background PHP workers, Queue brokers
PHP
1
star
90

cache

[READ ONLY] Common Cache Interfaces
PHP
1
star
91

mailer

[READ ONLY] Mailing Interfaces. Subtree split of the Spiral Mailer component (see spiral/framework)
PHP
1
star
92

broadcasting

[READ ONLY] Common Broadcasting Interfaces
PHP
1
star
93

nyholm-bridge

Nylohm PSR-7/PSR-17 bridge support.
PHP
1
star
94

writeaway

PHP API server for WriteAway editor
PHP
1
star