#2657·frankenphp

Follow-ups for the background worker stack

Author: nicolas-grekasCreated Sep 18, 2026Updated Sep 21, 2026

Things left to do or decide after #2617 and its stack, so they don't get lost.

  • Validate a configuration before stopping the running one: frankenphp.Validate() reports what Init() would refuse without starting anything, and the Caddy app implements caddy.Validator on it, so a rejected reload leaves the running site serving. Done in #2661.

  • Synchronize the startup-failure boundary: publishing ShuttingDown wakes the startup waiter before the thread finished its exit path, so Init() can move on while a thread is still unwinding. Both worker handlers share that path. The other half of this, a shutdown request reaching a thread that already ended on its own, is fixed in #2664. https://github.com/php/frankenphp/pull/2617#discussion_r3987787784

  • Pull the rest of the common bookkeeping into workerLifecycle once that boundary has one shape. https://github.com/php/frankenphp/pull/2617#discussion_r3987787771

  • Stop making people compute the thread budget by hand: num_threads now counts the threads for the requests no worker serves, workers coming on top, in #2660. No new option in the end, max_threads keeps bounding the whole process.

  • Implement Io\Poll\Handle on FrankenPHP\WorkerHandle and the task handles, done in #2617 and #2636 on top of the 8.6 job of #2658

  • Make the per-task php_stream of #2636 optional: the state of each side moved onto its handle, the task settles in the handle's cleanup, and getStream() builds the stream on demand, so a script waiting through a context allocates neither a stream nor a resource per task. Done in #2636.

  • Recycle the task handles: measured and dropped. A per-thread pool of the per-side state benches flat against #2636 (39.1 -> 38.7us a task, throughput within 1.4% either way, 15.4 syscalls on both sides, fork run 35466429028), since the engine already recycles the object slot and what is left is one 72-byte block per side.

  • Give macOS the channel Linux gets from eventfd: done in #2636 with a kqueue descriptor carrying an EVFILT_USER event, one per side. Measured on a macos-latest runner before writing it, per wake-up round trip: socketpair 16.1us, two pipes 14.0us, kqueue 11.7us, the same quarter eventfd takes off the pair on Linux (23.1 -> 17.5us on the same runner class). Windows keeps the socket pair for php_select().

  • Bound the wait for a background worker to become ready: boot_timeout on the worker, 30s by default, the figure max_execution_time already enforces where Zend timers exist, 0 to wait forever. The worker is drained and stopped through its boot-failure path and Init() names it. Done in #2617, which needed #2664 first, since a worker that gave up on its boot could not be shut down.