• This repository has been archived on 25/May/2020
  • Stars
    star
    120
  • Rank 290,384 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 5 years ago
  • Updated about 4 years ago

Reviews

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

Repository Details

[ABANDONED] Moved to https://github.com/spiral/roadrunner-laravel

This package is abandoned and no longer maintained
We suggests using the spiral/roadrunner-laravel package instead

RoadRunner ⇆ Laravel bridge

Version Version Build Status Coverage Downloads count License

Easy way for connecting RoadRunner and Laravel applications.

Installation

Require this package with composer using next command:

$ composer require avto-dev/roadrunner-laravel "^3.3"

Installed composer is required (how to install composer).

You need to fix the major version of package.

Previous major versions still available, but it's development is abandoned. Use only latest major version!

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

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

And basic RoadRunner configuration file (./.rr.yaml.dist):

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

After that you can modify configuration files as you wish.

Important: despite the fact that worker allows you to refresh application instance on each HTTP request (if environment variable APP_REFRESH set to true), we strongly recommend to avoid 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.

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 outcoming responses using laravel events system. Also events 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:

env:
  #APP_REFRESH: true

http:
  address: 0.0.0.0:8080
  workers:
    command: 'php ./vendor/bin/rr-worker'

static:
  dir: 'public'

Roadrunner server starting:

$ rr -c ./.rr.yaml serve -d

Listeners

This package provides event listeners for resetings 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.

Environment variables

You can use the following environment variables:

Variable name Description
APP_FORCE_HTTPS (declared in configuration file) Forces application HTTPS schema usage
APP_REFRESH Refresh application instance on every request

Known issues

Controller constructors

You should avoid to use HTTP controller constructors (created or resolved instances in constructor can be shared between different requests). Use dependencies resolving in 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 will find any package errors, please, make an issue in current repository.

License

This is open-sourced software licensed under the MIT License.

More Repositories

1

markdown-lint

Linter for markdown (with presets)
JavaScript
69
star
2

app-version-laravel

Laravel application versioning
PHP
26
star
3

bank-card-vue-component

Vue.js component with bank card
JavaScript
11
star
4

amqp-rabbit-laravel-queue

RabbitMQ (amqp-ext based) laravel queue driver
PHP
8
star
5

back2front-laravel

Package for backend -> frontend communication in Laravel applications
PHP
7
star
6

json-rpc-laravel

JSON-RPC 2.0 for Laravel applications
PHP
7
star
7

open-rpc-docs-builder-docker

React application to build documentation from OpenRPC schema
TypeScript
6
star
8

events-log-laravel

Events logging for laravel applications
PHP
5
star
9

stacked-dumper-laravel

Stacked variables dumper for Laravel-based application
PHP
5
star
10

composer-cleanup-plugin

Composer plugin for cleaning up unused files from packages.
PHP
5
star
11

dev-tools

[ABANDONED] PHP developer tools
PHP
4
star
12

app-metrics-laravel

Metrics for Laravel applications
PHP
4
star
13

smspilot-notifications-laravel

Notifications channel for SMS Pilot service
PHP
3
star
14

vehicle-logotypes

Vehicle logotypes set
PHP
3
star
15

php-cs-fixer

A tool to automatically fix PHP code style
PHP
3
star
16

cloud-payments-laravel

The package provides easy way to use Cloud Payments API
PHP
3
star
17

b2b-api-php-laravel

[ABANDONED] Laravel package for a working with package "avto-dev/b2b-api-php"
PHP
3
star
18

identity-laravel

IDEntity for Laravel
PHP
3
star
19

idea-settings

IntelliJ platform-based IDE shared settings
2
star
20

extended-laravel-validator

Extended validation rules for Laravel applications
PHP
2
star
21

b2b-api-php

[ABANDONED] PHP package for a working with B2B API service
PHP
2
star
22

faker-providers

Extended faker package providers
PHP
2
star
23

amqp-rabbit-manager

RabbitMQ (amqp-ext based) manager
PHP
2
star
24

data-migrations-laravel

Package for database data migrations
PHP
1
star
25

static-references-data

Data for static references
PHP
1
star
26

static-references-laravel

Static references for Laravel applications
PHP
1
star
27

go-simple-fileserver

Simple file server for Golang application
Go
1
star
28

release-tools-docker

[ABANDONED] Dockerized release tools
1
star