The Game Panel Design record
The Game Panel
ADR-0009 Accepted

Run as a FrankenPHP worker in a single binary

Created
Decided
Versions
History

Context

The panel is one system, shipped as a single binary, as ADR-0001 decides.

The people who host the panel install and run it themselves. A PHP application is usually installed as a project: the right PHP version, its extensions, its Composer dependencies and a web server all have to be in place before it runs, as they do for Pterodactyl. That is a high barrier to entry.

A PHP application served the usual way also boots again for every request, and throws away everything it built once the response is sent.

Decision

I will distribute the panel as a single binary built with FrankenPHP, with the whole application compiled into it, so that it is installed as a product rather than set up as a project. It will run in FrankenPHP's worker mode with Caddy underneath: the application will boot once, and one long-running process will serve every request. The engine will commit to this one runtime, and will abstract over no server API it will never run under.

Alternatives

Installing the panel as a PHP project, as Pterodactyl is installed, with whoever installs it providing the right PHP version, the Composer dependencies and the rest. I rejected this because it is a much higher barrier to entry than a single binary.

Other PHP runtimes. I rejected them because FrankenPHP can compile the entire application into a single binary, which is what lets the panel be distributed as an installable product. Which runtimes were weighed against it is not recorded.

Booting the application for every request. I rejected this because a long-running worker process is more efficient.

Abstracting over server APIs, so that the engine could run under more than one. I rejected this because the panel only ever runs inside this binary, so the engine commits to one runtime instead.

Consequences

Easier:

  • The panel will install as one file, with no PHP version, extensions or Composer dependencies to provide.
  • Caddy will handle TLS and certificate management, HTTP/2, HTTP/3, compression, static files and reverse proxying, so the engine will not.
  • Work done at boot will be done once for the life of a worker, rather than once for every request.

Harder:

  • Anything cached at boot will be shared by every request for the life of the worker, and anything cached during a request will leak into the next one unless something ends it.
  • Lifetimes will change meaning without any code changing: a shared instance will last until the worker restarts, not until the end of the request.
  • Every PHP extension the application or its dependencies require will have to be compiled into the binary.

Constrained:

  • Code will only ever run inside FrankenPHP's worker, so nothing will be written for any other server API.
  • Anything holding request state will need an explicit scope that ends with the request.

Sources

  • Issue #31, Engine - Config - TOML, original text of in its edit history: the first written record of the panel being distributed as a binary using FrankenPHP. The decision, worker mode included, was taken at the start of the project on a date not recalled, so this first record is both created and decided.
  • The reasons, that FrankenPHP can compile the entire application into a single binary so that the panel can be distributed as an installable product, that installing the panel as a PHP project, as Pterodactyl is installed, is a high barrier to entry, and that a long-running worker process is more efficient, and worker mode being decided at the start of the project: first written down on , with no record of when they were weighed.
  • Issue #62, Engine - HTTP, : worker mode with Caddy underneath, committing to one runtime rather than abstracting over server APIs, what Caddy handles, and what a long-running worker forces on cached state, taken from what followed rather than anticipated.
  • Issue #63, Engine - Container - Binding lifetimes, : shared instances lasting until the worker restarts rather than until the end of the request, taken from what followed rather than anticipated.
  • PR #75, chore: Rename package, add licence and patch Composer CVE, merged and squashed as 3372f20: extensions a dependency declares having to be compiled into the single-binary build, taken from what followed rather than anticipated.
  • Commit 0d62ceb, "Correct README badges and repository framing", : the README recording the FrankenPHP worker runtime.

Source adr/0009-frankenphp-worker.md · commit d6910e4 · exported