-
Notifications
You must be signed in to change notification settings - Fork 20
RoadRunner 2.9 | Yii2 Configuration with yii app basic
Charles R. Portwood II edited this page Aug 1, 2023
·
2 revisions
Tested April 2022.
.rr.yaml
---
http:
address: "0.0.0.0:8081"
pool.debug: true
middleware: [ "static" ]
static:
dir: "./web"
rpc:
enable: true
server:
command: ./web/roadrunner
env:
YII_ALIAS_WEB: "http://127.0.0.1:8081"
YII_ALIAS_WEBROOT: ./web
web/roadrunner
#!/usr/bin/env php
<?php
ini_set('display_errors', 'stderr');
// Set your normal YII_ definitions
defined('YII_DEBUG') or define('YII_DEBUG', true);
// Alternatives set this in your rr.yaml file
//defined('YII_DEBUG') or define('YII_DEBUG', \getenv('YII_DEBUG'));
defined('YII_ENV') or define('YII_ENV', 'dev');
// Alternatives set this in your rr.yaml file
//defined('YII_ENV') or define('YII_ENV', \getenv('YII_ENV'));
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';
$worker = Spiral\RoadRunner\Worker::create();
$psrServerFactory = new Laminas\Diactoros\ServerRequestFactory();
$psrStreamFactory = new Laminas\Diactoros\StreamFactory();
$psrUploadFileFactory = new Laminas\Diactoros\UploadedFileFactory();
$psr7 = new Spiral\RoadRunner\Http\PSR7Worker($worker, $psrServerFactory, $psrStreamFactory, $psrUploadFileFactory);
$config = require __DIR__ . '/../config/web.php';
$application = (new \yii\Psr7\web\Application($config));
// Handle each request in a loop
try {
while ($request = $psr7->waitRequest()) {
if (($request instanceof Psr\Http\Message\ServerRequestInterface)) {
try {
$response = $application->handle($request);
$psr7->respond($response);
} catch (\Throwable $e) {
$psr7->getWorker()->error((string)$e);
}
if ($application->clean()) {
$psr7->getWorker()->stop();
return;
}
}
}
} catch (\Throwable $e) {
$psr7->getWorker()->error((string)$e);
}
composer.json
"require": {
"php": ">=5.6.0",
"yidas/yii2-bower-asset": "2.0.13.1",
"yiisoft/yii2": "~2.0.14",
"yiisoft/yii2-bootstrap4": "~2.0.0",
"yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0",
"charlesportwoodii/yii2-psr7-bridge": "dev-master",
"spiral/roadrunner": "^2.9"
}
web/config.php
[
'aliases' => [
'@bower' => '@vendor/yidas/yii2-bower-asset/bower',
'@npm' => '@vendor/npm-asset',
],
'request' => [
'class' => \yii\Psr7\web\Request::class,
'enableCookieValidation' => false,
'enableCsrfValidation' => false,
'enableCsrfCookie' => false,
'cookieValidationKey' => 'foo',
'parsers' => [
'application/json' => \yii\web\JsonParser::class,
]
],
'response' => [
'class' => \yii\Psr7\web\Response::class,
'charset' => 'UTF-8'
],
'urlManager' => [
'class' => \yii\web\UrlManager::class,
'showScriptName' => false,
'enableStrictParsing' => false,
'enablePrettyUrl' => true
]
]