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.
- ✅ 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.
composer require yii2-extensions/franken-php:^0.1.0@dev
Create your FrankenPHP entry point (public/index.php
)
<?php
declare(strict_types=1);
use yii2\extensions\frankenphp\FrankenPHP;
use yii2\extensions\psrbridge\http\StatelessApplication;
// production default (change to 'true' for development)
defined('YII_DEBUG') or define('YII_DEBUG', false);
// production default (change to 'dev' for development)
defined('YII_ENV') or define('YII_ENV', 'prod');
require_once dirname(__DIR__) . '/vendor/autoload.php';
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();
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
}
}
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 run your application, you can use the following command.
cd web
./frankenphp php-server --worker index.php
Docker image require public
directory to be mounted as /app/public
and the application root directory as /app
.
Alternatively, Docker images are available.
Gitbash/Windows
docker run \
-e FRANKENPHP_CONFIG="worker ./public/index.php" \
-v "//k/yii2-extensions/basic-frankenphp/Caddyfile:/etc/caddy/Caddyfile" \
-v "//k/yii2-extensions/basic-frankenphp:/app" \
-v "//k/yii2-extensions/basic-frankenphp/web:/app/public" \
-p 80:80 \
-p 443:443 \
-p 443:443/udp \
--name yii2-frankenphp-worker \
dunglas/frankenphp:php8.3-alpine
Note: Paths in the example (
//k/yii2-extensions/basic-frankenphp
) are for demonstration purposes only.
Replace them with the actual path to your Yii2 project on your system.
Linux/WSL
docker run \
-e FRANKENPHP_CONFIG="worker ./public/index.php" \
-v $PWD/Caddyfile:/etc/caddy/Caddyfile \
-v $PWD:/app \
-v $PWD/web:/app/public \
-p 80:80 \
-p 443:443 \
-p 443:443/udp \
--name yii2-frankenphp-worker \
dunglas/frankenphp:php8.3-alpine
To use the runkit7
extension, you need to install it in the Docker container. You can do this by executing the
following commands inside the container.
docker exec -it yii2-frankenphp-worker bash
apk add --no-cache autoconf alpine-sdk php8-dev git
pecl install runkit7-4.0.0a6
echo "extension=runkit7.so" > /usr/local/etc/php/conf.d/runkit7.ini
Note:
runkit7
extension is required to allow redefining theYII_BEGIN_TIME
constant on every request in worker mode.
Your application will be available at https://localhost
(HTTPS by default) and you can access it via HTTP/2 or HTTP/3.
For detailed configuration options and advanced usage.