[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
[![Version][badgepackagistversion]][linkpackagist] [![Version][badgephpversion]][link_packagist] [![Build Status][badgebuildstatus]][linkbuildstatus] [![Coverage][badgecoverage]][linkcoverage] [![Downloads count][badgedownloadscount]][link_packagist] [![License][badgelicense]][link_license]
Easy way for connecting [RoadRunner][roadrunner] and [Laravel][laravel] applications.
Require this package with composer using next command:
shell script $ composer require avto-dev/roadrunner-laravel "^3.3"
Installed
composeris required ([how to install composer][getcomposer]).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:
shell script $ php ./artisan vendor:publish --provider='AvtoDev\RoadRunnerLaravel\ServiceProvider' --tag=config
And basic RoadRunner configuration file (
./.rr.yaml.dist):
shell script $ 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 `APPREFRESH
set totrue`), 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.
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][laravel_events]. Also events contains:
Event classname |
Application object | HTTP server request | HTTP request | HTTP response | Exception |
---|
BeforeLoopStartedEvent| ✔ | | | |
BeforeLoopIterationEvent| ✔ | ✔ | | |
BeforeRequestHandlingEvent| ✔ | | ✔ | |
AfterRequestHandlingEvent| ✔ | | ✔ | ✔ |
AfterLoopIterationEvent| ✔ | | ✔ | ✔ |
AfterLoopStoppedEvent| ✔ | | | |
LoopErrorOccurredEvent| ✔ | ✔ | | | ✔
Simple
.rr.yamlconfig example:
env: #APP_REFRESH: truehttp: address: 0.0.0.0:8080 workers: command: 'php ./vendor/bin/rr-worker'
static: dir: 'public'
Roadrunner server starting:
shell script $ rr -c ./.rr.yaml serve -d
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.
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
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:
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:
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);// ... }
}
You should never to use middleware constructor for
session,
session.store,
author auth
Guardinstances resolving and storing in properties (for example). Use method-injection or access them through
Requestinstance.
Bad:
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:
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); }
}
For package testing we use
phpunitframework and
docker-ce+
docker-composeas develop environment. So, just write into your terminal after repository cloning:
shell script $ make build $ make latest # or 'make lowest' $ make test
[![Release date][badgereleasedate]][linkreleases] [![Commits since latest release][badgecommitssince_release]][linkcommits]
Changes log can be [found here][linkchangeslog].
[![Issues][badgeissues]][link_issues] [![Issues][badgepulls]][link_pulls]
If you will find any package errors, please, [make an issue][linkcreateissue] in current repository.
This is open-sourced software licensed under the [MIT License][link_license].
[badgepackagistversion]:https://img.shields.io/packagist/v/avto-dev/roadrunner-laravel.svg?maxAge=180 [badgephpversion]:https://img.shields.io/packagist/php-v/avto-dev/roadrunner-laravel.svg?longCache=true [badgebuildstatus]:https://travis-ci.org/avto-dev/roadrunner-laravel.svg?branch=master [badgecoverage]:https://img.shields.io/codecov/c/github/avto-dev/roadrunner-laravel/master.svg?maxAge=60 [badgedownloadscount]:https://img.shields.io/packagist/dt/avto-dev/roadrunner-laravel.svg?maxAge=180 [badgelicense]:https://img.shields.io/packagist/l/avto-dev/roadrunner-laravel.svg?longCache=true [badgereleasedate]:https://img.shields.io/github/release-date/avto-dev/roadrunner-laravel.svg?style=flat-square&maxAge=180 [badgecommitssincerelease]:https://img.shields.io/github/commits-since/avto-dev/roadrunner-laravel/latest.svg?style=flat-square&maxAge=180 [badgeissues]:https://img.shields.io/github/issues/avto-dev/roadrunner-laravel.svg?style=flat-square&maxAge=180 [badgepulls]:https://img.shields.io/github/issues-pr/avto-dev/roadrunner-laravel.svg?style=flat-square&maxAge=180 [linkreleases]:https://github.com/avto-dev/roadrunner-laravel/releases [linkpackagist]:https://packagist.org/packages/avto-dev/roadrunner-laravel [linkbuildstatus]:https://travis-ci.org/avto-dev/roadrunner-laravel [linkcoverage]:https://codecov.io/gh/avto-dev/roadrunner-laravel/ [linkchangeslog]:https://github.com/avto-dev/roadrunner-laravel/blob/master/CHANGELOG.md [linkissues]:https://github.com/avto-dev/roadrunner-laravel/issues [linkcreateissue]:https://github.com/avto-dev/roadrunner-laravel/issues/new/choose [linkcommits]:https://github.com/avto-dev/roadrunner-laravel/commits [linkpulls]:https://github.com/avto-dev/roadrunner-laravel/pulls [linklicense]:https://github.com/avto-dev/roadrunner-laravel/blob/master/LICENSE [getcomposer]:https://getcomposer.org/download/ [roadrunner]:https://github.com/spiral/roadrunner [laravel]:https://laravel.com [laravel_events]:https://laravel.com/docs/events [#10]:https://github.com/avto-dev/roadrunner-laravel/issues/10