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

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

    View 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 Slide

  5. Symfony and Containers

    View 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 Slide

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

    View 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 Slide

  9. © sergioska
    FPM and
    containers

    View Slide

  10. Can We Do
    Better?!

    View 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 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 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 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 Slide

  15. Getting Started

    View Slide

  16. Getting Started

    View 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 Slide

  18. 🧪 Symfony CLI X FrankenPHP

    View 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 Slide

  20. Worker Script

    View Slide

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

    View Slide

  22. The Runtime Component

    View Slide

  23. Symfony App in Worker Mode

    View 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 Slide

  25. 103 Early
    Hints

    View Slide

  26. Typical
    Web Page
    © Google

    View Slide

  27. 103 Early
    Hints
    © Google

    View Slide

  28. Early Hints: Not Possible With PHP

    View Slide

  29. Early Hints: Possible With Go
    👋

    View Slide

  30. Early Hints: Supported by FrankenPHP ⚡

    View Slide

  31. Early Hints: Symfony 6.3 ⚡

    View Slide

  32. Real-time

    View Slide

  33. FrankenPHP includes a Mercure hub!

    View Slide

  34. ➔ 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 Slide

  35. ➔ 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 Slide

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

    View Slide