charlesportwoodii / yii2-psr7-bridge Goto Github PK
View Code? Open in Web Editor NEWA PSR7 Bridge and PSR-15 adapter for Yii2
License: BSD 3-Clause "New" or "Revised" License
A PSR7 Bridge and PSR-15 adapter for Yii2
License: BSD 3-Clause "New" or "Revised" License
'aliases' => [
'@bower' => '@vendor/yidas/yii2-bower-asset/bower',
]
/dist/js/bootstrap.bundle.js not fond
I have 'enablePrettyUrl' => true, 'showScriptName' => false
, and 'news/<type:\w+>' => 'news/index'
rule in my urlManager
config. While using FPM approach, I can get type
param (when accessing /news/some-type
URL) by calling Yii::$app->request->get('type')
. When using yii\Psr7\web\Request
and your bridge, I get nulls on every get()
or post()
call.
Could you please describe how to get it working?
version: '3'
server:
command: "php ./worker.php"
env:
- YII_ALIAS_WEBROOT: "./web"
- YII_ALIAS_WEB: "./"
rpc:
listen: tcp://127.0.0.1:6001
http:
address: :8088
pool:
num_workers: 8
# Debug mode for the pool. In this mode, pool will not pre-allocate the worker.
# Worker (only 1, num_workers ignored) will be allocated right after the request arrived.
debug: false
middleware: ["static", "headers"]
static:
dir: "./web"
forbid: [".php", ".htaccess"]
headers:
response:
"Cache-Control": "no-cache"
logs:
mode: production
level: warn
Hi!
How fully disable sessions (using authclient with REST)? It always sends cookie.
yii2-psr7-bridge/src/web/Application.php
Lines 115 to 132 in 94c3c46
composer.json
"require": {
"spiral/roadrunner": "^2023.1.0",
"spiral/roadrunner-http": "^v3.0.0",
"spiral/roadrunner-worker": "^3.0.0",
"spiral/roadrunner-cli": "^2.5.0",
"spiral/roadrunner-grpc": "^3.0.0",
"psr/http-message": "1.0.1",
"charlesportwoodii/yii2-psr7-bridge": "dev-master",
"psr/http-server-handler": "^1.0",
"laminas/laminas-diactoros": "^2.3"
},
"replace": {
"yidas/yii2-bower-asset": "2.0.13.1"
},
web.php
'request' => [
'class' => \yii\Psr7\web\Request::class,
'cookieValidationKey' => '123456',
],
'response' => [
'class' => \yii\Psr7\web\Response::class
],
.rr.yaml
version: '3'
server:
command: "php ./worker.php"
env:
- YII_ALIAS_WEBROOT: "./web"
- YII_ALIAS_WEB: "./"
rpc:
listen: tcp://127.0.0.1:6001
http:
address: :8088
pool:
num_workers: 8
# Debug mode for the pool. In this mode, pool will not pre-allocate the worker.
# Worker (only 1, num_workers ignored) will be allocated right after the request arrived.
debug: false
middleware: ["static", "headers"]
static:
dir: "./web"
forbid: [".php", ".htaccess"]
headers:
response:
"Cache-Control": "no-cache"
logs:
mode: production
level: warn
worker.php
#!/usr/bin/env php
<?php
ini_set('display_errors', 'stderr');
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'dev');
// 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'));
// comment out the following two lines when deployed to production
//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);
}
Hi, first thanks for this bridge.
Does this version work with RR 2.0+ ?
If yes, can you show me a code for the main loop in worker.php?
Thanks
See the issue: yiisoft/yii2#19738
I suppose, the framework could handle its memory consumption by its own, but hopefully, we can come up with some solution on the bridge layer. Creating and killing the app with every request is not the desired solution, I guess.
/**
* Handles exceptions and errors thrown by the request handler
*
* @param \Throwable|\Exception $exception
* @return ResponseInterface
*/
private function handleError(\Throwable $exception) : ResponseInterface
{
$response = $this->getErrorHandler()->handleException($exception);
$this->trigger(self::EVENT_AFTER_REQUEST);
$this->state = self::STATE_END;
return $response->getPsr7Response();
}
$this->getErrorHandler()->handleException() this is void method. it is not returned response
support sendFile and sendStreamAsFile for Response, it is ok with workerman ,hope to provide an idea,
use GuzzleHttp\Psr7\Utils;
class Response extends \yii\Psr7\web\Response
{
/**
* {@inheritDoc}
*/
public function sendStreamAsFile($handle, $attachmentName, $options = [])
{
$response = parent::sendStreamAsFile($handle, $attachmentName, $options);
$this->stream = Utils::streamFor($this->stream[0]);
return $response;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.