yiisoft / yii-runner-rapira
Web application runner for Rapira worker mode
Requires
- php: 8.4 - 8.5
- psr/container: ^2.0
- psr/http-message: ^1.0 || ^2.0
- psr/log: ^2.0 || ^3.0
- rapira/contract: @dev
- rapira/http: ^0.1.2
- yiisoft/di: ^1.0
- yiisoft/error-handler: ^4.0
- yiisoft/psr-emitter: ^1.0
- yiisoft/yii-http: ^1.0
- yiisoft/yii-runner: ^2.2
Requires (Dev)
- ext-curl: *
- friendsofphp/php-cs-fixer: ^3.95.1
- httpsoft/http-message: ^1.0
- infection/infection: ^0.35.4
- internal/dload: ^1.16
- llm/skills: ^1.9
- psr/event-dispatcher: ^1.0
- psr/http-factory: ^1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
- rapira/testing: ^0.1.4
- rector/rector: ^2.6.3
- shipmonk/composer-dependency-analyser: ^1.8
- testo/assert: ^0.1.13
- testo/bridge-infection: ^0.1.8
- testo/filter: ^0.1.6
- testo/lifecycle: ^0.1.5
- testo/test: ^0.1.6
- testo/testo: ^0.10.41
- vimeo/psalm: ^6.1
- yiisoft/code-style: ^1.0
- yiisoft/config: ^1.1
- yiisoft/definitions: ^3.0
- yiisoft/http: ^1.2
- yiisoft/injector: ^1.2
- yiisoft/middleware-dispatcher: ^5.0
- yiisoft/router: ^4.0
- yiisoft/router-fastroute: ^4.0
- yiisoft/test-support: ^3.0
- yiisoft/yii-event: ^2.2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-17 18:27:07 UTC
README
Yii Rapira runner
The package contains a bootstrap for running a Yii3 application under Rapira, a PHP application server with PHP embedded in the process.
Note
To serve the application with PHP-FPM or another classic SAPI, use yiisoft/yii-runner-http, the default runner of yiisoft/app and yiisoft/app-api.
Requirements
- PHP 8.4 - 8.5.
Installation
The package could be installed with Composer:
composer require yiisoft/yii-runner-rapira
General usage
In your application root create worker.php:
<?php declare(strict_types=1); use App\Environment; use Psr\Log\LogLevel; use Yiisoft\ErrorHandler\ErrorHandler; use Yiisoft\ErrorHandler\Renderer\PlainTextRenderer; use Yiisoft\Log\Logger; use Yiisoft\Log\StreamTarget; use Yiisoft\Yii\Runner\Rapira\RapiraApplicationRunner; $root = __DIR__; require_once $root . '/src/bootstrap.php'; $runner = new RapiraApplicationRunner( rootPath: $root, debug: Environment::appDebug(), checkEvents: Environment::appDebug(), environment: Environment::appEnv(), temporaryErrorHandler: new ErrorHandler( new Logger( [ (new StreamTarget())->setLevels([ LogLevel::EMERGENCY, LogLevel::ERROR, LogLevel::WARNING, ]), ], ), new PlainTextRenderer(), ), ); $runner->run();
Create a rapira.toml next to it:
[http] listen = "127.0.0.1:8000" [pool] entrypoint = "worker.php" mode = "worker"
Then start the server:
rapira serve
See the Rapira documentation for the full list of configuration options.
Modes
Rapira runs the entry script in one of three modes, chosen by [pool] mode. The runner detects the mode at
startup and serves accordingly, so the same worker.php works in every one of them:
classic— one process per request, the way PHP-FPM works. Handy for debugging: nothing survives between requests.worker— a long-lived process serving requests one after another through the SAPI superglobals.dispatcher— a long-lived process taking requests from the Rapira dispatcher and writing responses back through it, without the SAPI in between.
In worker and dispatcher modes the process outlives the request, so stateful services must be reset
between requests. For resetters configuration, see
Yii DI StateResetter documentation. To recycle
a process after a number of handled requests, set max_requests in the [pool] section of rapira.toml.
Configuration
By default, the RapiraApplicationRunner is configured to work with Yii application templates and follows the
config groups convention. The constructor
parameters let you point it at other config groups, directories and a custom temporary error handler or
emitter; every parameter is documented on the constructor itself.
If the configuration instance settings differ from the default, you can specify a customized configuration instance:
/** * @var Yiisoft\Config\ConfigInterface $config * @var Yiisoft\Yii\Runner\Rapira\RapiraApplicationRunner $runner */ $runner = $runner->withConfig($config);
The default container is Yiisoft\Di\Container. But you can specify any implementation
of the Psr\Container\ContainerInterface:
/** * @var Psr\Container\ContainerInterface $container * @var Yiisoft\Yii\Runner\Rapira\RapiraApplicationRunner $runner */ $runner = $runner->withContainer($container);
Documentation
If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.
License
The Yii Rapira Runner is free software. It is released under the terms of the BSD License.
Please see LICENSE for more information.
Maintained by Yii Software.