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

  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
  3. Web and Cloud Experts ➔ 100% employee-owned co-op ✊ ➔

    Democratically managed 💬 ➔ 70 people 🦄 ➔ Distributed company 🌎 ➔ [email protected] 💌
  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
  5. Symfony and Containers

  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) ➔ …
  7. ➔ Simple ➔ Web server + PHP = 1 service

    ➔ Default solution for containers DRAWBACKS: ➔ Works only with Apache ➔ Less performant than FPM Apache Module
  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
  9. © sergioska FPM and containers

  10. Can We Do Better?!

  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
  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
  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
  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
  15. Getting Started

  16. Getting Started

  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
  18. 🧪 Symfony CLI X FrankenPHP

  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
  20. Worker Script

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

    is started.
  22. The Runtime Component

  23. Symfony App in Worker Mode

  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!
  25. 103 Early Hints

  26. Typical Web Page © Google

  27. 103 Early Hints © Google

  28. Early Hints: Not Possible With PHP

  29. Early Hints: Possible With Go 👋

  30. Early Hints: Supported by FrankenPHP ⚡

  31. Early Hints: Symfony 6.3 ⚡

  32. Real-time

  33. FrankenPHP includes a Mercure hub!

  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
  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?!
  36. Try it, give it a star on GitHub... … and

    win Laury’s merch at our booth! Thanks! frankenphp.dev @dunglas