How to integrate an existing Mezzio application with RoadRunner.
Create worker entry point bin/roadrunner-worker.php:
<?php
declare(strict_types=1);
chdir(dirname(__DIR__));
require 'vendor/autoload.php';
$app = (static function (): \Mezzio\Application {
$container = require 'config/container.php';
assert($container instanceof Psr\Container\ContainerInterface);
$app = $container->get(\Mezzio\Application::class);
$factory = $container->get(\Mezzio\MiddlewareFactory::class);
(require 'config/pipeline.php')($app, $factory, $container);
(require 'config/routes.php')($app, $factory, $container);
return $app;
})();
$worker = new Spiral\RoadRunner\Http\PSR7Worker(
Spiral\RoadRunner\Worker::create(),
new Laminas\Diactoros\ServerRequestFactory(),
new Laminas\Diactoros\StreamFactory(),
new Laminas\Diactoros\UploadedFileFactory(),
);
while ($req = $worker->waitRequest()) {
try {
$response = $app->handle($req);
$worker->respond($response);
} catch (\Throwable $e) {
$worker->getWorker()->error((string)$e);
}
}Require the RoadRunner PHP library:
composer require spiral/roadrunner "^2.0"Download the RoadRunner Server binary:
vendor/bin/rr get --location bin/
chmod +x bin/rrCreate .rr.yaml:
server:
command: "php -dopcache.enable_cli=1 -dopcache.validate_timestamps=0 bin/roadrunner-worker.php"
http:
address: "0.0.0.0:8080"
pool:
num_workers: 8
logs:
mode: production
channels:
http:
level: info # Log all http requests, set to info to disable
server:
level: debug # Everything written to worker stderr is logged
metrics:
level: error
# Uncomment to use rpc integration
# rpc:
# listen: tcp://127.0.0.1:6001
# Uncomment to use metrics integration
# metrics:
# # prometheus client address (path /metrics added automatically)
# address: "0.0.0.0:9180"Create .rr.dev.yaml:
server:
command: "php bin/roadrunner-worker.php"
http:
address: "0.0.0.0:8080"
logs:
mode: development
channels:
http:
level: debug # Log all http requests, set to info to disable
server:
level: debug # Everything written to worker stderr is logged
metrics:
level: debug
reload:
enabled: true
interval: 1s
patterns: [".php", ".yaml"]
services:
http:
dirs: ["."]
recursive: trueRun RoadRunner with ./bin/rr serve or ./bin/rr serve -c .rr.dev.yaml (watch/dev mode).
The MIT License (MIT). Please see License File for more information.