# FrankenPHP

> Runs the FrankenPHP worker loop for a Yii PSR bridge application.

[API reference](/docs/api/index.md) › [FrankenPHP](/docs/extensions/franken-php/reference/index.md) › FrankenPHP

| final class | `yii2\extensions\frankenphp\FrankenPHP` |
| --- | --- |
| Source | [`src/FrankenPHP.php`](https://github.com/yii2-extensions/franken-php/blob/main/src/FrankenPHP.php#L23) |

Runs the FrankenPHP worker loop for a Yii PSR bridge application.

Creates a PSR request from SAPI globals, emits the response, and finalizes the bridge lifecycle once per request.
HEAD responses omit the body. See the README quick start for the entry script and required factory bindings.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a new instance of the [`FrankenPHP`](/docs/extensions/franken-php/reference/frankenphp/index.md) class. | `FrankenPHP` |
| [`run()`](#method-run) | Runs the FrankenPHP worker loop for handling HTTP requests. | `FrankenPHP` |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-DEFAULT_MAX_REQUESTS"></span>`DEFAULT_MAX_REQUESTS` | `1000` | Default maximum number of requests to handle before stopping the worker loop. | `FrankenPHP` |

## Method details

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

```php
public function __construct(yii2\extensions\psrbridge\http\Application $app, int|null $maxRequests = null)
```

Creates a new instance of the [`FrankenPHP`](/docs/extensions/franken-php/reference/frankenphp/index.md) class.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$app` | [`yii2\extensions\psrbridge\http\Application`](/docs/extensions/psr-bridge/reference/http/application/index.md) | Application instance. |
| `$maxRequests` | `int\|null` | Maximum number of requests to handle before stopping. If `null`, will try to read from `$_ENV['MAX_REQUESTS']` or the process environment, otherwise defaults to '1000'. |

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

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

Runs the FrankenPHP worker loop for handling HTTP requests.

**Returns**

`int`: Exit code indicating the result of the worker loop execution ([`ServerExitCode::OK`](/docs/extensions/psr-bridge/reference/http/serverexitcode/index.md#case-OK) for success, [`ServerExitCode::REQUEST_LIMIT`](/docs/extensions/psr-bridge/reference/http/serverexitcode/index.md#case-REQUEST_LIMIT) for request limit reached).

**Throws**

- [`Throwable`](https://www.php.net/manual/en/class.throwable.php): if an exception occurs during request handling or response emission.