Search by

yiisoft / yii-runner-rapira

samdarkvjik

Web application runner for Rapira worker mode

Package info

github.com/yiisoft/yii-runner-rapira

Homepage

Chat

Forum

Wiki

pkg:composer/yiisoft/yii-runner-rapira

Fund package maintenance!

Opencollective

yiisoft

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-master 2026-09-17 18:25 UTC

This package is auto-updated.

Last update: 2026-09-17 18:27:07 UTC


README

Yii

Yii Rapira runner


Latest Stable Version Total Downloads Build status Code Coverage Mutation testing badge static analysis type-coverage

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.

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack