diff --git a/README.md b/README.md index 560676ac..abe317db 100644 --- a/README.md +++ b/README.md @@ -85,8 +85,8 @@ high-performance worker modes. Long-running PHP workers for higher throughput and lower latency. -[![FrankenPHP](https://img.shields.io/badge/FrankenPHP-777BB4?style=for-the-badge&logo=php&logoColor=white)](https://github.com/yii2-extensions/app-basic/tree/franken-php) -[![RoadRunner](https://img.shields.io/badge/RoadRunner-%23FF6B35.svg?style=for-the-badge&logo=data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTEyIDJMMjIgMTJMMTIgMjJMMiAxMkwxMiAyWiIgZmlsbD0iI0ZGRkZGRiIvPgo8cGF0aCBkPSJNOCAyTDE2IDEwTDggMThaIiBmaWxsPSIjRkY2QjM1Ii8+CjxwYXRoIGQ9Ik0xNiA2TDIwIDEwTDE2IDE0WiIgZmlsbD0iI0ZGNkIzNSIvPgo8L3N2Zz4K&logoColor=white)](https://github.com/yii2-extensions/app-basic/tree/road-runner) +[![FrankenPHP](https://img.shields.io/badge/FrankenPHP-777BB4?style=for-the-badge&logo=php&logoColor=white)](https://github.com/yii2-extensions/franken-php) +[![RoadRunner](https://img.shields.io/badge/RoadRunner-%23FF6B35.svg?style=for-the-badge&logo=data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTEyIDJMMjIgMTJMMTIgMjJMMiAxMkwxMiAyWiIgZmlsbD0iI0ZGRkZGRiIvPgo8cGF0aCBkPSJNOCAyTDE2IDEwTDggMThaIiBmaWxsPSIjRkY2QjM1Ii8+CjxwYXRoIGQ9Ik0xNiA2TDIwIDEwTDE2IDE0WiIgZmlsbD0iI0ZGNkIzNSIvPgo8L3N2Zz4K&logoColor=white)](https://github.com/yii2-extensions/road-runner) ### Installation diff --git a/docs/configuration.md b/docs/configuration.md index e1cdf21a..35d4396f 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -2,8 +2,161 @@ ## Overview +This guide covers all configuration options for the PSR Bridge extension, from +basic setup to advanced HTTP message handling, worker mode integration, and +stateless application configuration. + ## Basic configuration +### Core components setup + +Replace the default Yii2 Request and Response components with PSR Bridge +enhanced versions. + +```php + [ + 'request' => [ + 'class' => Request::class, + 'enableCookieValidation' => false, + 'enableCsrfValidation' => false, + ], + 'response' => [ + 'class' => Response::class, + ], + 'errorHandler' => [ + 'class' => ErrorHandler::class, + ], + ], +]; +``` + +## Error handling configuration + +```php + [ + 'class' => ErrorHandler::class, + 'errorAction' => 'site/error', + 'discardExistingOutput' => true, +], +``` + +### Custom error views and formats + +```php + [ + 'class' => ErrorHandler::class, + 'errorView' => '@app/views/error.php', + 'exceptionView' => '@app/views/exception.php', + 'callStackItemView' => '@app/views/callStackItem.php', + 'displayVars' => ['_GET', '_POST', '_FILES', '_COOKIE'], +], +``` + +### Memory management configuration + +Configure memory limits and garbage collection behavior. + +```php +flushLogger = true; + +// Memory management example +if ($app->clean()) { + // Memory usage exceeded 90% of limit + // Trigger worker restart or cleanup + exit(0); +} +``` + +### PSR-7 factory dependencies + +Configure PSR-7 HTTP message factories for request/response conversion. + +```php + [ + 'definitions' => [ + ResponseFactoryInterface::class => ResponseFactory::class, + ServerRequestFactoryInterface::class => ServerRequestFactory::class, + StreamFactoryInterface::class => StreamFactory::class, + UploadedFileFactoryInterface::class => UploadedFileFactory::class, + ], +], +``` + +### StatelessApplication configuration + +For worker-based environments (FrankenPHP, RoadRunner). + +```php + 'stateless-app', + 'basePath' => dirname(__DIR__), + 'controllerNamespace' => 'app\\controllers', + 'components' => [ + 'request' => [ + 'class' => Request::class, + 'workerMode' => true, + ], + 'response' => [ + 'class' => Response::class, + ], + // ... other components + ], +]; + +$app = new StatelessApplication($config); +``` + ## Next steps - 💡 [Usage Examples](examples.md)