yii2-extensions/psr-bridge
Composer 安装命令:
composer require yii2-extensions/psr-bridge
包简介
PSR-7 bridge for Yii2 with worker mode support
关键字:
README 文档
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.
Features
Installation
composer require yii2-extensions/psr-bridge:^0.3
Quick start
Worker mode (FrankenPHP)
<?php declare(strict_types=1); // disable PHP automatic session cookie handling ini_set('session.use_cookies', '0'); require_once dirname(__DIR__) . '/vendor/autoload.php'; use yii2\extensions\frankenphp\FrankenPHP; use yii2\extensions\psrbridge\http\Application; // Load environment variables from .env file $dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__)); $dotenv->safeLoad(); // production default (change to 'true' for development) define('YII_DEBUG', filter_var($_ENV['YII_DEBUG'] ?? false, FILTER_VALIDATE_BOOLEAN)); // 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'; $app = new Application($config); $runner = new FrankenPHP($app); $runner->run();
Worker mode (RoadRunner)
<?php declare(strict_types=1); require __DIR__ . '/../vendor/autoload.php'; use yii2\extensions\psrbridge\http\Application; use yii2\extensions\roadrunner\RoadRunner; define('YII_DEBUG', filter_var(getenv('YII_DEBUG'), FILTER_VALIDATE_BOOLEAN)); define('YII_ENV', getenv('YII_ENV') ?? 'prod'); require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php'; $config = require dirname(__DIR__) . '/config/web/app.php'; $app = new Application($config); $runner = new RoadRunner($app); $runner->run();
PSR-7 Conversion
// 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);
Note
This shows the low-level conversion API. Serving a full request in a long-running worker goes through the
handle() → emit → finalize() cycle (or a runner). See
Response lifecycle finalization.
Worker lifecycle defaults
In long-running workers, keep Application lifecycle defaults unless you have a specific requirement:
useSession=truesyncCookieValidation=trueresetUploadedFiles=true
Warning
Keep request-scoped components (request, response, errorHandler, session, user) out of
Application::$persistentComponents.
Components listed in Application::$persistentComponents (defaults to db and cache) keep loaded instances across
requests.
Define lifecycle flags before run() (via config or property setters).
$config = [ 'class' => Application::class, // disable session and cookie validation sync for stateless REST APIs. // keep resetUploadedFiles=true (default) for request isolation. '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.
Package information
Quality code
Our social networks
License
yii2-extensions/psr-bridge 适用场景与选型建议
yii2-extensions/psr-bridge 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.53k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2025 年 07 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「yii2」 「yii2-extension」 「psr-7」 「psr-17」 「roadrunner」 「frankenphp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yii2-extensions/psr-bridge 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yii2-extensions/psr-bridge 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yii2-extensions/psr-bridge 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Model of a web-based resource
A custom URL rule class for Yii 2 which allows to create translated URL rules
A Yii2 extension for a bootstrap wizard
Interfaces for web resource models and services to retrieve and create them
The yii2-videojs-widget is a Yii 2 wrapper for the [video.js](http://www.videojs.com/). A JavaScript and CSS library that makes it easier to work with and build on HTML5 video. This is also known as an HTML5 Video Player.
yii2 hit counter
统计信息
- 总下载量: 8.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 26
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2025-07-18