https://github.com/yii2-extensions/psr-bridge
Transform your Yii2 applications into high-performance, PSR-compliant powerhouses.
https://github.com/yii2-extensions/psr-bridge
emitter frankenphp psr7 roadrunner stateless worker yii2 yii2-extensions
Last synced: 4 months ago
JSON representation
Transform your Yii2 applications into high-performance, PSR-compliant powerhouses.
- Host: GitHub
- URL: https://github.com/yii2-extensions/psr-bridge
- Owner: yii2-extensions
- License: other
- Created: 2025-07-13T16:05:23.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2026-02-17T14:24:26.000Z (4 months ago)
- Last Synced: 2026-02-17T18:50:31.662Z (4 months ago)
- Topics: emitter, frankenphp, psr7, roadrunner, stateless, worker, yii2, yii2-extensions
- Language: PHP
- Homepage:
- Size: 606 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
PSR bridge
Transform your Yii2 applications into high-performance, PSR-compliant powerhouses
Supporting traditional SAPI, RoadRunner, FrankenPHP, and worker-based architectures
## Available deployment options
### High-Performance Worker Mode
Long-running PHP workers for higher throughput and lower latency.
[](https://github.com/yii2-extensions/franken-php)
[](https://github.com/yii2-extensions/road-runner)
## Features

### Installation
```bash
composer require yii2-extensions/psr-bridge:^0.2
```
### Quick start
#### Worker mode (FrankenPHP)
```php
safeLoad();
// production default (change to 'true' for development)
define('YII_DEBUG', $_ENV['YII_DEBUG'] ?? false);
// production default (change to 'dev' for development)
define('YII_ENV', $_ENV['YII_ENV'] ?? 'prod');
require_once dirname(__DIR__) . '/vendor/yiisoft/yii2/Yii.php';
$config = require_once dirname(__DIR__) . '/config/web/app.php';
$runner = new FrankenPHP(new Application($config));
$runner->run();
```
#### Worker mode (RoadRunner)
```php
run();
```
#### PSR-7 Conversion
```php
// Convert Yii2 request to PSR-7
$request = Yii::$app->request;
$psr7Request = $request->getPsr7Request();
// Convert Yii2 response to PSR-7
$response = Yii::$app->response;
$psr7Response = $response->getPsr7Response();
// Emit PSR-7 response
$emitter = new yii2\extensions\psrbridge\emitter\SapiEmitter();
$emitter->emit($psr7Response);
```
### Worker lifecycle defaults
In long-running workers, keep `Application` lifecycle defaults unless you have a specific requirement:
- `useSession=true`
- `syncCookieValidation=true`
- `resetUploadedFiles=true`
> [!WARNING]
> `Application::prepareForRequest()` calls `reinitializeApplication()` on each request, so values provided in the
> application config array are reapplied and take precedence over post-construction property assignments.
>
> Configure lifecycle flags in the config array when possible.
```php
$config = [
'class' => Application::class,
// disable session and cookie validation sync for stateless REST APIs; keep resetUploadedFiles=true (the default)
// unless you have a specific reason to retain uploaded file state across requests
'useSession' => false,
'syncCookieValidation' => false,
'resetUploadedFiles' => true,
];
```
### Smart Body Parsing
The bridge automatically parses incoming PSR-7 request bodies based on the `Content-Type` header and your configured
parsers (for example, `application/json`), ensuring `Yii::$app->request->post()` works seamlessly in worker mode without
extra boilerplate.
## Documentation
For detailed configuration options and advanced usage.
- ๐ [Installation Guide](docs/installation.md)
- โ๏ธ [Configuration Reference](docs/configuration.md)
- ๐ก [Usage Examples](docs/examples.md)
- ๐งช [Testing Guide](docs/testing.md)
- ๐ ๏ธ [Development Guide](docs/development.md)
## Package information
[](https://www.php.net/releases/8.1/en.php)
[](https://github.com/yiisoft/yii2/tree/2.0.53)
[](https://github.com/yiisoft/yii2/tree/22.0)
[](https://packagist.org/packages/yii2-extensions/psr-bridge)
[](https://packagist.org/packages/yii2-extensions/psr-bridge)
## Quality code
[](https://codecov.io/github/yii2-extensions/psr-bridge)
[](https://github.com/yii2-extensions/psr-bridge/actions/workflows/static.yml)
[](https://github.com/yii2-extensions/psr-bridge/actions/workflows/linter.yml)
[](https://github.styleci.io/repos/1019044094?branch=main)
## Our social networks
[](https://x.com/Terabytesoftw)
## License
[](LICENSE)