# RoadRunner

> Runs the RoadRunner request loop for a Yii PSR bridge application.

[API reference](/docs/api/index.md) › [RoadRunner](/docs/extensions/road-runner/reference/index.md) › RoadRunner

| final class | `yii2\extensions\roadrunner\RoadRunner` |
| --- | --- |
| Source | [`src/RoadRunner.php`](https://github.com/yii2-extensions/road-runner/blob/main/src/RoadRunner.php#L20) |

Runs the RoadRunner request loop for a Yii PSR bridge application.

See also: [`Application`](/docs/extensions/psr-bridge/reference/http/application/index.md) (for the PSR bridge application implementation.).

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a new instance of the [`RoadRunner`](/docs/extensions/road-runner/reference/roadrunner/index.md) class. | `RoadRunner` |
| [`run()`](#method-run) | Processes requests from the configured [`Application`](/docs/extensions/psr-bridge/reference/http/application/index.md) instance until the worker returns `null`. | `RoadRunner` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(yii2\extensions\psrbridge\http\Application $app)
```

Creates a new instance of the [`RoadRunner`](/docs/extensions/road-runner/reference/roadrunner/index.md) class.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$app` | [`yii2\extensions\psrbridge\http\Application`](/docs/extensions/psr-bridge/reference/http/application/index.md) | PSR bridge application instance. |

### run() <span id="method-run"></span>

```php
public function run(): int
```

Processes requests from the configured [`Application`](/docs/extensions/psr-bridge/reference/http/application/index.md) instance until the worker returns `null`.

Reports failures through `error()` only while the response has not been emitted. Finalization runs once in
`finally`, passing `false` when processing or emission fails. Memory is checked after either outcome.

Recycling declines the next dispatch before handling it, allowing RoadRunner to retry it in a fresh worker.
Streaming read and finalization failures propagate after this handshake without a second request outcome;
any transport failure during shutdown is retained as the previous exception. A further emission failure
while closing an already-failed stream propagates immediately after finalization without another outcome.

**Returns**

`int`: Exit code indicating successful execution ([`ServerExitCode::OK`](/docs/extensions/psr-bridge/reference/http/serverexitcode/index.md#case-OK)).

**Throws**

- [`Throwable`](https://www.php.net/manual/en/class.throwable.php): When streaming, worker transport, or application finalization fails.