$30 off During Our Annual Pro Sale. View Details »

The PHP Revolution Is Underway: FrankenPHP 1.0 Beta

The PHP Revolution Is Underway: FrankenPHP 1.0 Beta

I'm very proud to announce the immediate availability of FrankenPHP 1.0 beta.

FrankenPHP is a brand-new application server for PHP, written in Go and built on top of Caddy, that dramatically simplifies the deployment of PHP apps, and brings new features to PHP such as:

- a worker mode that improves typical application performance by a factor of 3
- native support for HTTP/3
- native support for the 103 Early Hints HTTP status code (assets preloading)
- automatic HTTPS certificate generation and renewal
- native support for the Mercure protocol (real-time data broadcasting)
- and much more!

FrankenPHP is available as a Docker image (Debian, Alpine, PHP 8.2, and PHP 8.3 variants are available) and as standalone binaries with 0 dependencies for Linux and macOS.

Kévin Dunglas

September 21, 2023
Tweet

More Decks by Kévin Dunglas

Other Decks in Programming

Transcript

  1. API PLATFORM CON 2023 - LILLE, FRANCE & ONLINE

    View Slide

  2. The New PHP Era
    01
    02
    03
    04
    The State of PHP
    API Platform 3.2
    What’s Next

    View Slide

  3. About Me
    ✔ API Platform creator
    ✔ Les-Tilleuls.coop co-founder
    ✔ Polyglot developer
    Kévin Dunglas
    [email protected]
    @dunglas
    dunglas.dev

    View Slide

  4. The State
    of PHP
    A bit dated

    View Slide

  5. PHP FPM
    Web Browser Web Server
    (NGINX, Caddy, …)
    HTTP
    REQUEST
    HTTP
    RESPONSE
    PHP-FPM
    PHP processes
    FASTCGI
    REQUEST
    FASTCGI
    RESPONSE

    View Slide

  6. Deploying PHP Apps
    ✖ PHP doesn’t speak HTTP directly
    ✖ PHP must be bridged with a web server
    ✖ PHP-FPM is the most popular Server API
    (SAPI)
    - External server using the FastCGI protocol
    ✖ Alternative: mod_php for Apache:
    - Not compatible or not recommended with
    modern Apache

    View Slide

  7. Deploying PHP Apps: Summary
    ✖ Unlike alternatives (e.g. Node), PHP has no
    built-in HTTP server
    ✖ PHP-FPM needs a 3rd-party web server
    ✖ This implies:
    ○ At least 2 services
    ○ A shared file (UNIX socket, best
    option) or a network link between the
    FPM and the web server

    View Slide

  8. PHP Apps: Onboarding
    Local installation is complex, all users need:
    ✖ PHP-FPM
    ✖ A web server
    ✖ Same versions on every machine, and in
    prod
    ✖ Same configuration on every machine,
    and in prod
    ✖ Fortunately, Docker helps: API Platform
    distribution, Symfony Docker, Laravel
    Sail…
    NEW DEVS
    NOT WELCOME

    View Slide

  9. PHP Apps: Docker / Kubernetes
    © sergioska

    View Slide

  10. PHP Performance
    ✔ The language itself is now very fast (faster
    than Python or Ruby)
    ✖ But PHP is “fire and forget”
    ✖ Everything that is built to handle a request is
    then destroyed when the request is handled:
    - Symfony kernel
    - Symfony DIC
    - Services
    - In memory caches…

    View Slide

  11. PHP Real-time
    ✖ PHP isn’t designed to support
    long-running connections
    (max_execution_time, no direct access to
    the network layer…)
    ✖ WebSocket, SSE, WebTransport and the
    like are not (or badly) supported by
    typical PHP setups
    ✖ It’s the same for other advanced/modern
    HTTP features (e.g. 103 Early Hints)

    View Slide

  12. The New
    PHP Era
    The Modern Prometheus

    View Slide

  13. Introducing FrankenPHP 1.0 beta

    View Slide

  14. The Modern PHP App Server
    ✔ All in one HTTP server with native, vanilla, PHP
    support
    ✔ Cloud Native
    ✔ Built with Docker in mind…
    ✔ …but also available as a standalone static binary
    ✔ Worker mode
    ✔ Native Mercure support
    ✔ Early Hints and much more!

    View Slide

  15. Web Browser
    PHP Threads
    Only One Service
    HTTP
    REQUEST
    HTTP
    RESPONSE

    View Slide

  16. Moderner PHP Than Ever
    ✔ The official PHP executor is embedded in
    a state-of-the-art web server: Caddy
    ✔ Native support for HTTP 1, 2 and 3
    ✔ Automatic HTTPS certificates generation
    and renewal (Let’s Encrypt or ZeroSSL)
    ✔ Copy your PHP files in the document root,
    that’s all!
    ✔ Popular PHP extensions, including
    OPcache and XDebug, are natively
    supported!

    View Slide

  17. Docker Images
    $ docker run .:/app/public dunglas/frankenphp
    ✔ Exposes the current directory (as php -S)
    ✔ Built on top of official PHP Images
    ✔ PHP 8.2 and 8.3 variants
    ✔ Install PHP extensions as usual
    ✔ An Alpine variant exists
    (default: Debian)

    View Slide

  18. One Binary To Rule Them All

    View Slide

  19. One Binary To Rule Them All
    $ ./frankenphp run --config /my/Caddyfile
    ✔ Exposes the current directory (as php -S)
    ✔ Static binary (no dependencies)
    ✔ Caddy, FrankenPHP, PHP and all popular PHP
    extensions are embedded
    ✔ Available for macOS and Linux

    View Slide

  20. Worker Mode
    ✔ Boot your application once and keep it in memory!
    ✔ Process incoming requests without having to boot your app again
    ✔ Compatible with API Platform and Symfony thanks
    to Symfony Runtime
    ✔ Written in C and Go (awesome concurrency engine)
    ✔ According to our benchmarks, 3.5x faster than FPM
    with API Platform
    ✔ Unlike alternatives (RoadRunner, Swoole…)
    ○ entirely optional: typical apps still work
    with FrankenPHP
    ○ runs in process: no network calls
    ○ uses plain old superglobals: no need for PSR-7 etc

    View Slide

  21. Worker Mode

    View Slide

  22. Real-time: Built-in Mercure Hub

    View Slide

  23. 103 Early Hints

    View Slide

  24. Already Popular

    View Slide

  25. ❤ Free Software

    View Slide

  26. FrankenPHP and
    API Platform
    Best Friends Forever

    View Slide

  27. API Platform 3.2 Beta Is Out!
    $ gh repo create my-project \
    --clone --private \
    --template api-platform/api-platform
    $ cd my-project
    $ docker compose up --wait

    View Slide

  28. 3.2 Includes FrankenPHP
    ✔ Key feature: FrankenPHP is now part of the API
    Platform distribution
    ✔ Prod mode (Kubernetes, Docker Compose…) uses
    FrankenPHP workers
    ✔ The distribution has been dramatically simplified:
    only 1 core service for PHP
    ✔ You don’t have to change a single line of code!
    ✔ An FPM variant is still provided (for now)

    View Slide

  29. Other Docker Improvements
    ✔ 6x times faster builds
    ✔ Cached layers reused across builds when using
    GitHub Actions
    ✔ Simplified and improved Dockerfiles
    ✔ Symfony Docker also benefits from FrankenPHP and
    these improvements

    View Slide

  30. Before:

    View Slide

  31. Now: 7x Faster

    View Slide

  32. Native OAuth and OIDC support

    View Slide

  33. Groundbreaking WASM-based
    runnable documentation

    View Slide

  34. Improved DTO system

    View Slide

  35. Better Extensibility And
    Dozens of Other Improvements

    View Slide

  36. What’s
    Next
    Still Some Work To Do

    View Slide

  37. Known Issues With FrankenPHP
    ✖ Fibers aren’t reliable (work in progress, in the Go
    runtime)
    ✖ Crashes when building the Symfony cache with the
    Alpine Variant (use Debian for now)
    ✖ Doctrine isn’t 100% reliable in worker mode (work in
    progress)

    View Slide

  38. Going One Step Further

    View Slide

  39. FOLLOW ME!
    @dunglas
    dunglas.dev / frankenphp.dev / api-platform.com
    Thank you!
    Any questions?

    View Slide