An open API service indexing awesome lists of open source software.

https://github.com/yii2-extensions/franken-php

Supercharge your Yii2 applications with FrankenPHP blazing-fast HTTP server.
https://github.com/yii2-extensions/franken-php

frankenphp psr-7 worker yii2 yii2-extensions

Last synced: 4 months ago
JSON representation

Supercharge your Yii2 applications with FrankenPHP blazing-fast HTTP server.

Awesome Lists containing this project

README

          





Yii Framework

FrankenPHP





PHPUnit


Mutation Testing


PHPStan


Supercharge your Yii2 applications with FrankenPHP blazing-fast HTTP server

HTTP/2, HTTP/3, automatic memory management, and worker mode for ultimate performance

## Features


Feature Overview

## Demo

[![Template](https://img.shields.io/badge/Template-App%20Basic-74AA9C?style=for-the-badge&logo=yii&logoColor=white)](https://github.com/yii2-extensions/app-basic/tree/franken-php)

Explore the ready-to-run Yii2 + FrankenPHP application template.

### Installation

```bash
composer require yii2-extensions/franken-php:^0.1.0@dev
```

### Quick start

Create your FrankenPHP entry point (`web/index.php`)

```php
safeLoad();

// production default (change to 'true' for development)
define('YII_DEBUG', $_ENV['YII_DEBUG'] ?? false);
// production default (change to 'dev' for development)
define('YII_ENV', $_ENV['YII_ENV'] ?? 'prod');

require_once dirname(__DIR__) . '/vendor/yiisoft/yii2/Yii.php';

$config = require_once dirname(__DIR__) . '/config/web.php';

$runner = new FrankenPHP(new StatelessApplication($config));

$runner->run();
```

### FrankenPHP configuration

Create `Caddyfile` in your project root (worker mode)

```caddyfile
{
auto_https off
admin localhost:2019
https_port 8443

frankenphp {
worker ./web/index.php
}
}

localhost {
tls ./web/ssl/localhost.pem ./web/ssl/localhost-key.pem

log

encode zstd br gzip

root ./web

# compatibility headers to enable X-Sendfile support in PHP frameworks (Yii2/Symfony)
# see: https://github.com/php/frankenphp/blob/main/docs/x-sendfile.md
request_header X-Sendfile-Type x-accel-redirect
request_header X-Accel-Mapping ../private-files=/private-files

intercept {
@sendfile header X-Accel-Redirect *
handle_response @sendfile {
root private-files/
rewrite * {resp.header.X-Accel-Redirect}
method * GET
header -X-Accel-Redirect
file_server
}
}

php_server {
try_files {path} index.php
}
}
```

> [!WARNING]
> **Note:** Using custom certificates (like `tls ./web/ssl/localhost.pem ./web/ssl/localhost-key.pem`) avoids browser trust warnings that occur with Caddy's automatic self-signed certificates.
> For local development, consider using [mkcert](https://github.com/FiloSottile/mkcert) to generate trusted local certificates.
> If you want to use Caddy's automatic self-signed certificates for local development, you can remove this line.

### Standalone Binary

We provide static FrankenPHP binaries for Linux and macOS containing [PHP 8.4](https://www.php.net/releases/8.4/en.php)
and most popular PHP extensions.

On Windows, use [WSL](https://learn.microsoft.com/windows/wsl/) to run FrankenPHP.

[Download FrankenPHP](https://github.com/php/frankenphp/releases) or copy this line into your terminal to automatically
install the version appropriate for your platform.

```bash
curl https://frankenphp.dev/install.sh | sh
mv frankenphp /usr/local/bin/
```

To run your application, you can use the following command.

```bash
./frankenphp run --config ./Caddyfile --watch
```

### Docker

Alternatively, [Docker images](https://frankenphp.dev/docs/docker/) are available.

#### Worker mode

Gitbash/Windows

```bash
docker run \
-e CADDY_GLOBAL_OPTIONS="auto_https off" \
-e CADDY_SERVER_EXTRA_DIRECTIVES="tls /app/web/ssl/localhost.pem /app/web/ssl/localhost-key.pem" \
-e FRANKENPHP_CONFIG="worker ./web/index.php" \
-e SERVER_NAME="https://localhost:8443" \
-e SERVER_ROOT="./web" \
-v "//k/yii2-extensions/app-basic:/app" \
-p 8443:8443 \
-p 8443:8443/udp \
--name yii2-frankenphp-worker \
dunglas/frankenphp
```

> **Note:** Paths in the example (`//k/yii2-extensions/app-basic`) are for demonstration purposes only.
> Replace them with the actual path to your Yii2 project on your system.

Linux/WSL

```bash
docker run \
-e CADDY_GLOBAL_OPTIONS="auto_https off" \
-e CADDY_SERVER_EXTRA_DIRECTIVES="tls /app/web/ssl/localhost.pem /app/web/ssl/localhost-key.pem" \
-e FRANKENPHP_CONFIG="worker ./web/index.php" \
-e SERVER_NAME="https://localhost:8443" \
-e SERVER_ROOT="./web" \
-v $PWD:/app \
-p 8443:8443 \
-p 8443:8443/udp \
--name yii2-frankenphp-worker \
dunglas/frankenphp
```

> [!IMPORTANT]
> Your application will be available at `https://localhost:8443` or at the address set in the `Caddyfile`.

### Development & Debugging

For enhanced debugging capabilities and proper time display in FrankenPHP, install the worker debug extension.

```bash
composer require --dev yii2-extensions/worker-debug:^0.1
```

Add the following to your development configuration (`config/web.php`):

```php
WorkerDebugModule::class,
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
}
```

### File Upload Handling

For enhanced file upload support in worker environments, use the PSR-7 bridge UploadedFile class instead of the standard
Yii2 implementation.

```php
error === UPLOAD_ERR_OK) {
$file->saveAs('@webroot/uploads/' . $file->name);
}

return $this->asJson(['status' => 'uploaded']);
}
}
```

## Documentation

For detailed configuration options and advanced usage.

- ๐Ÿ“š [Installation Guide](docs/installation.md)
- โš™๏ธ [Configuration Reference](docs/configuration.md)
- ๐Ÿงช [Testing Guide](docs/testing.md)
- ๐Ÿ› ๏ธ [Development Guide](docs/development.md)

## Package information

[![PHP](https://img.shields.io/badge/%3E%3D8.1-777BB4.svg?style=for-the-badge&logo=php&logoColor=white)](https://www.php.net/releases/8.1/en.php)
[![Yii 2.0.x](https://img.shields.io/badge/2.0.53-0073AA.svg?style=for-the-badge&logo=yii&logoColor=white)](https://github.com/yiisoft/yii2/tree/2.0.53)
[![Yii 22.0.x](https://img.shields.io/badge/22.0.x-0073AA.svg?style=for-the-badge&logo=yii&logoColor=white)](https://github.com/yiisoft/yii2/tree/22.0)
[![Latest Stable Version](https://img.shields.io/packagist/v/yii2-extensions/franken-php.svg?style=for-the-badge&logo=packagist&logoColor=white&label=Stable)](https://packagist.org/packages/yii2-extensions/franken-php)
[![Total Downloads](https://img.shields.io/packagist/dt/yii2-extensions/franken-php.svg?style=for-the-badge&logo=composer&logoColor=white&label=Downloads)](https://packagist.org/packages/yii2-extensions/franken-php)

## Quality code

[![Codecov](https://img.shields.io/codecov/c/github/yii2-extensions/franken-php.svg?style=for-the-badge&logo=codecov&logoColor=white&label=Coverage)](https://codecov.io/github/yii2-extensions/franken-php)
[![PHPStan Level Max](https://img.shields.io/badge/PHPStan-Level%20Max-4F5D95.svg?style=for-the-badge&logo=php&logoColor=white)](https://github.com/yii2-extensions/franken-php/actions/workflows/static.yml)
[![Super-Linter](https://img.shields.io/github/actions/workflow/status/yii2-extensions/franken-php/linter.yml?style=for-the-badge&label=Super-Linter&logo=github)](https://github.com/yii2-extensions/franken-php/actions/workflows/linter.yml)
[![StyleCI](https://img.shields.io/badge/StyleCI-Passed-44CC11.svg?style=for-the-badge&logo=styleci&logoColor=white)](https://github.styleci.io/repos/1031393416?branch=main)

## Our social networks

[![Follow on X](https://img.shields.io/badge/-Follow%20on%20X-1DA1F2.svg?style=for-the-badge&logo=x&logoColor=white&labelColor=000000)](https://x.com/Terabytesoftw)

## License

[![License](https://img.shields.io/badge/License-BSD--3--Clause-brightgreen.svg?style=for-the-badge&logo=opensourceinitiative&logoColor=white&labelColor=555555)](LICENSE)