Skip to content

dunglas/frankenphp-demo

Repository files navigation

FrankenPHP Demo

A demo app using FrankenPHP that uses Symfony and API Platform.

Installation

Composer

Install composer dependencies:

docker run --rm -it -v $PWD:/app composer:latest install

Or if you have composer installed locally:

composer install

The project

Run the project with Docker (worker mode):

docker run \
    -e FRANKENPHP_CONFIG="worker ./public/index.php" \
    -v $PWD:/app \
    -p 80:80 -p 443:443/tcp -p 443:443/udp \
    --name FrankenPHP-demo \
    dunglas/frankenphp

PS: Docker is optional; you can also compile FrankenPHP by yourself.

Create the database (It uses a local SQLite database stored in var/data.db):

docker exec -it FrankenPHP-demo php bin/console doctrine:migrations:migrate --no-interaction

Then you can access the application:

This demo is a standard Symfony application and works without FrankenPHP. Therefore, you can serve it with the Symfony CLI:

symfony serve

The repository also includes a benchmark comparing FrankenPHP and PHP-FPM.

Package as a Standalone Binary

The demo app can be packaged as a self-contained binary containing the Symfony app, FrankenPHP and the PHP extensions used by the app.

To do so, the easiest way is to use the provided Dockerfile:

docker build -t static-app -f static-build.Dockerfile .
docker cp $(docker create --name static-app-tmp static-app):/go/src/app/dist/frankenphp-linux-x86_64 frankenphp-demo ; docker rm static-app-tmp

The resulting binary is the frankenphp-demo file in the current directory. It can be started with the following commands:

chmod  x ./frankenphp-demo
./frankenphp-demo php-server

It's also possible to run commands with ./frankenphp-demo php-cli bin/console.