Upgrade to Pro — share decks privately, control downloads, hide ads and more …

FrankenPHP: a modern app server for PHP and Symfony apps

FrankenPHP: a modern app server for PHP and Symfony apps

FrankenPHP is a modern application server for PHP built in Go. FrankenPHP gives superpowers to your PHP apps: Early Hints, worker mode, real-time capabilities, automatic HTTPS, HTTP/2, and HTTP/3 support...

How does Symfony fit with FrankenPHP? What benefits does it bring to the Symfony ecosystem?

Symfony Runtime, Symfony HttpFoundation, Symfony Mercure, Symfony Local Web Server... let's see how the Symfony ecosystem can leverage FrankenPHP for the sake of performance and simplicity!

This is a variant of: https://dunglas.dev/2022/10/frankenphp-the-modern-php-app-server-written-in-go/

Kévin Dunglas

November 17, 2022
Tweet

More Decks by Kévin Dunglas

Other Decks in Programming

Transcript

  1. A modern app server
    for PHP and Symfony
    https://frankenphp.dev

    View full-size slide

  2. ➔ PHP
    API Platform creator,
    Symfony maintainer
    ➔ GO
    Go core contributor, Mercure.rocks
    and Vulcain.rocks creator
    ➔ C
    PHP core contributor
    Kévin Dunglas:
    Polyglot Dev
    @dunglas

    View full-size slide

  3. Web and Cloud Experts
    ➔ 100% employee-owned co-op ✊
    ➔ Democratically managed 💬
    ➔ 70 people 🦄
    ➔ Distributed company 🌎
    [email protected] 💌

    View full-size slide

  4. FrankenPHP
    A modern app server for PHP
    and Symfony
    ➔ Built for containers
    ➔ Worker mode
    ➔ 103 Early Hints support
    ➔ Real-time support (Mercure module)
    ➔ Compatible with all existing PHP apps:
    progressive enhancement

    View full-size slide

  5. Symfony and Containers

    View full-size slide

  6. Containers: Which SAPI?
    Server Application Programming
    Interface: interface between the PHP
    interpreter and web servers
    ➔ Apache module
    ➔ FPM (FastCGI Process Manager)
    ➔ CGI (Common Gateway Interface)
    ➔ NGINX Unit (not the NGINX
    you’re used to)
    ➔ …

    View full-size slide

  7. ➔ Simple
    ➔ Web server + PHP = 1 service
    ➔ Default solution for containers
    DRAWBACKS:
    ➔ Works only with Apache
    ➔ Less performant than FPM
    Apache Module

    View full-size slide

  8. FPM
    ➔ Most popular SAPI
    ➔ Supported by most web servers:
    Caddy, NGINX, Apache…
    DRAWBACKS:
    ➔ External service
    ➔ Require a UNIX or a TCP socket
    ➔ Hard to containerize

    View full-size slide

  9. © sergioska
    FPM and
    containers

    View full-size slide

  10. Can We Do
    Better?!

    View full-size slide

  11. ➔ Perfect for containers
    ◆ Just 1 service
    ◆ No external dependencies
    ◆ Batteries included
    ➔ Contains the Caddy web server
    ◆ All Caddy features and modules
    ◆ Benefits from Go features
    ◆ Extensible: in Go, in C, in PHP
    ➔ Prod, CI and dev
    FrankenPHP: Modern PHP App Server

    View full-size slide

  12. ➔ Standalone Go library
    ➔ Embed PHP in your Go programs
    ➔ New SAPI for Go net/http
    ◆ Caddy, Symfony CLI, Traefik, K8S…
    ◆ Your custom Go app
    ➔ Caddy module using the library
    ➔ Unique features
    The ❤ of FrankenPHP: A New SAPI For Go

    View full-size slide

  13. ➔ Easy to configure
    ➔ Cloud native:
    API, hot config reloading…
    ➔ Automatic HTTPS
    ➔ HTTP/2, HTTP/3, Early Hints…
    ➔ Extensible with modules:
    Mercure, Vulcain, OAuth, OIDC…
    ➔ Prod ready
    ➔ Server of Symfony Docker
    ➔ Written in Go 😻: secure and fast
    Caddy: The New Kid on the Block

    View full-size slide

  14. ➔ Compatible with existing PHP apps!
    ➔ 1 service, 1 minimal Docker image 😍
    ➔ Also works without Docker
    ➔ Entirely configurable
    ◆ Caddyfile
    ◆ php.ini
    ➔ Free software
    (as in free speech ✊, and free beer 🍺)
    FrankenPHP: At a Glance

    View full-size slide

  15. Getting Started

    View full-size slide

  16. Getting Started

    View full-size slide

  17. Alternative: Symfony CLI
    ➔ Simple local web server
    ➔ Built-in TLS support
    ➔ Dev environments only
    ➔ Auto-detects and auto-configures:
    ● PHP FPM and CLI
    ● Docker Compose services: Postgres, MySQL,
    Mailcatcher, Redis, RabbitMQ…
    ➔ Works with any PHP app (even if not using SF)
    ➔ Written in Go 😻
    @dunglas

    View full-size slide

  18. 🧪 Symfony CLI X FrankenPHP

    View full-size slide

  19. FrankenPHP Superpower: The Worker Mode
    ➔ Boot your application once
    ➔ Keep it in memory
    ➔ Process incoming requests without having to
    boot your app again
    ➔ Relies on goroutines and channels
    ➔ Compatible with Symfony Runtime
    ➔ Somewhat similar to RoadRunner
    ➔ Unlike RoadRunner
    ◆ runs in process: no network calls,
    no gRPC
    ◆ uses plain old superglobals: no PSR-7

    View full-size slide

  20. Worker Script

    View full-size slide

  21. Starting the Worker Mode
    By default, one worker per CPU is started.

    View full-size slide

  22. The Runtime Component

    View full-size slide

  23. Symfony App in Worker Mode

    View full-size slide

  24. FrankenPHP: Worker Benchmark 🧪
    ➔ Setup:
    ◆ Hello World Symfony app (prod mode)
    ◆ Caddy Web Server (HTTP/2)
    ◆ 3000 requests, 100 connected users
    ◆ Benchmark tool: K6
    ➔ Average request duration:
    ◆ FPM: 9.45ms
    ◆ FrankenPHP (worker): 2.53ms
    ➔ Take it with a grain of salt, run your own!

    View full-size slide

  25. 103 Early
    Hints

    View full-size slide

  26. Typical
    Web Page
    © Google

    View full-size slide

  27. 103 Early
    Hints
    © Google

    View full-size slide

  28. Early Hints: Not Possible With PHP

    View full-size slide

  29. Early Hints: Possible With Go
    👋

    View full-size slide

  30. Early Hints: Supported by FrankenPHP ⚡

    View full-size slide

  31. Early Hints: Symfony 6.3 ⚡

    View full-size slide

  32. FrankenPHP includes a Mercure hub!

    View full-size slide

  33. ➔ Symfony (worker mode)
    ➔ API Platform (worker mode)
    ➔ Sulu (worker mode)
    ➔ Drupal
    ➔ Shopware
    ➔ WordPress
    ➔ All tested PHP extensions, including
    opcache and parallel
    Projects Known to Work With FrankenPHP

    View full-size slide

  34. ➔ Test, test and test again
    ➔ Release a stable version when PHP
    8.2 will be out
    ➔ 🚧 Add Windows support
    ➔ Add a built-in distributed HTTP cache
    server
    ➔ Add a built-in distributed cache
    system (like Memcache)
    ➔ Conquer the (PHP) world
    ➔ Contributions welcome!
    What’s next?!

    View full-size slide

  35. Try it,
    give it a star on GitHub...
    … and win Laury’s merch
    at our booth!
    Thanks!
    frankenphp.dev
    @dunglas

    View full-size slide