yii2-extensions/franken-php

Yii2 FrankenPHP runtime.

dev-main / 1.0.x-dev 2025-08-04 15:41 UTC

README

Yii Framework

Extension for FrankenPHP


PHP Version Yii2 2.0.53 Yii2 22.0 PHPUnit Mutation Testing Static Analysis

A blazing-fast FrankenPHP integration for Yii2 applications that provides seamless HTTP/2, HTTP/3, and WebSocket support with automatic memory management and real-time capabilities.

Features

  • Automatic HTTPS: Built-in automatic HTTPS with Let's Encrypt integration.
  • Early Hints: HTTP/2 Server Push and Early Hints support for faster loading.
  • Graceful Reloading: Hot reload capabilities without downtime.
  • HTTP/2 & HTTP/3 Support: Native support for modern HTTP protocols with multiplexing.
  • Memory Efficient: Smart memory management with configurable limits.
  • Production Ready: Battle-tested with Caddy's proven reliability.
  • Real-time Features: Server-Sent Events (SSE) and WebSocket support.
  • WebSocket Integration: Real-time bidirectional communication capabilities.
  • Worker Mode: Long-running worker processes for maximum performance.
  • Zero Configuration: Works out of the box with sensible defaults.

Quick start

Installation

composer require yii2-extensions/franken-php

Basic Usage

Create your FrankenPHP entry point (public/index.php):

<?php

declare(strict_types=1);

use yii2\extensions\frankenphp\FrankenPHP;
use yii2\extensions\psrbridge\http\StatelessApplication;

defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';

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

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

$runner->run();

FrankenPHP configuration

Create Caddyfile in your project root (worker mode).

{
    auto_https off
    admin localhost:2019

    frankenphp {
        worker ./index.php
    }
}

localhost {
    log

    encode zstd br gzip

    root public/

    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
    }
}

Standalone Binary

We provide static FrankenPHP binaries for Linux and macOS containing PHP 8.4 and most popular PHP extensions.

On Windows, use WSL to run FrankenPHP.

Download FrankenPHP or copy this line into your terminal to automatically install the version appropriate for your platform.

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

To serve the content of the current directory, run.

frankenphp php-server

You can also run command-line scripts with.

frankenphp php-cli /path/to/your/script.php

Docker

Alternatively, Docker images are available:

Clasic mode.

docker run -v .:/app/public \
    -p 80:80 -p 443:443 -p 443:443/udp \
    dunglas/frankenphp

Worker mode.

docker run -e FRANKENPHP_CONFIG="worker ./public/index.php" \ 
    -v $PWD/Caddyfile:/etc/caddy/Caddyfile \
    -v $PWD:/app \
    -p 80:80 \
    -p 443:443/tcp \
    -p 443:443/udp \
    --name yii2-frankenphp-rfc dunglas/frankenphp

Start the server

# start the server
./frankenphp run

# or with worker mode for production
./frankenphp run --worker public/index.php

Your application will be available at https://localhost (HTTPS by default) and you can access it via HTTP/2 or HTTP/3.

Documentation

For detailed configuration options and advanced usage:

Quality code

Latest Stable Version Total Downloads codecov phpstan-level StyleCI

Our social networks

X

License

License