PHP RFC Proposes Request Lifecycle Hooks After FrankenPHP Security Bugs

Shared Request Cleanup for PHP Workers and Extensions
The Drop Times graphic titled "Rethinking How PHP Handles Requests" explains new lifecycle hooks for persistent workers. A PHP workflow diagram shows request handling and cleanup steps including "Reset Request State" and "Handle Sessions" and "Prepare Next Request".

Long-running PHP application servers could gain a shared mechanism for managing individual HTTP requests under a Request for Comments (RFC) proposal opened on 9 November 2026 by FrankenPHP creator Kévin Dunglas. The proposal introduces engine functions and extension hooks that would allow compatible worker-based servers to manage request-specific state without maintaining separate implementations of PHP's internal cleanup procedures. It targets PHP 8.7 and remains under discussion.

The proposal addresses a limitation in PHP's existing request lifecycle. Traditional PHP execution starts and shuts down a script for each HTTP request, whereas worker-mode servers such as FrankenPHP keep scripts running across multiple requests. This allows applications to reuse initialized services, autoloaders and connections, reducing repeated startup work. However, PHP's existing initialization and shutdown handlers recognize the lifetime of the worker script rather than the separate HTTP requests it processes, leaving worker servers responsible for resetting request-specific information.

Dunglas identifies that responsibility as a source of security and memory-safety problems. The RFC points to a session ID leak that can occur when PHP's session extension is loaded as a shared module, because FrankenPHP can reset session globals only when it is built against the session headers. It also cites a use-after-free involving php://temp streams and a double-free during request cleanup. The RFC presents these defects as examples of the risk created when worker SAPIs duplicate only parts of PHP's request startup and shutdown logic.

The RFC proposes two optional extension hooks, request_begin and request_end, alongside the engine functions php_request_begin() and php_request_end(). These would allow a worker server to signal the start and completion of each HTTP request while keeping the main PHP script running. The functions would coordinate request cleanup, output handling and preparation of the next request, while extensions could use the hooks to release or initialize their own request-specific state.

The proposed cleanup is deliberately limited to information associated with an incoming request or its response. This includes request superglobals, except $_ENV, session state, request bodies and output-related information. Other state intentionally retained by a long-running application, such as autoloaders, registered callbacks and settings changed during execution, would remain available. The distinction matters because resetting all PHP state between requests would also remove much of the benefit of running persistent workers.

Dunglas has published an experimental PHP implementation covering the standard, session and filter extensions, along with a FrankenPHP implementation using the proposed functions. The approach could also be adopted by other worker-capable PHP Server Application Programming Interfaces (SAPIs), including Rapira, Turbine and bext. Extensions used for debugging, profiling and application monitoring, such as Xdebug, Datadog, Blackfire and Tideways, could eventually use the same hooks instead of relying on FrankenPHP-specific integrations.

The proposal does not cover every PHP runtime. RoadRunner, Swoole and Workerman use request loops through the command-line SAPI and cannot directly invoke the proposed engine functions because they do not control that interface. Conventional PHP-FPM and Apache execution would not need the hooks, and existing extensions would continue compiling without modification. The RFC also states that applications would not need userland code changes to accommodate the proposed internal refactoring.

For Drupal, the proposal addresses a lower-level problem than the application-state challenges associated with persistent workers. Drupal 11.4, released on 1 July 2026, adopted Symfony Runtime to separate application bootstrapping from request handling and provide a foundation for future integration with servers such as FrankenPHP. However, Drupal services can retain request-specific information when the same application kernel handles multiple requests. Drupal core issue #3626107 proposes allowing services to declare reset methods so request-dependent state can be cleared without rebuilding the entire service container.

That distinction limits what the PHP RFC could accomplish for Drupal. PHP engine hooks could help compatible worker servers and extensions manage lower-level request state, but they would not automatically reset Drupal's cached services or resolve problems involving application-specific request data. The DropTimes previously covered FrankenPHP 1.13.4 and its worker-mode security fixes on 2 November 2026. The new RFC concerns whether some of the cleanup responsibilities behind those problems should be handled centrally by PHP instead of individual servers.

The RFC also distinguishes its proposal from the separate PHP Scope RFC, which concerns request and task isolation during concurrent execution. Dunglas describes the lifecycle hooks as complementary because they would identify when an HTTP request ends, even when application objects or scopes remain in memory. The proposal requires a two-thirds majority for acceptance, but no voting date has been announced. Until accepted and implemented, the hooks remain a proposed change rather than functionality available in a stable PHP release.

Disclosure: This content is produced with the assistance of AI.

Note: The vision of this web portal is to help promote news and stories around the Drupal community and promote and celebrate the people and organizations in the community. We strive to create and distribute our content based on these content policy. If you see any omission/variation on this please reach out to us at #thedroptimes channel on Drupal Slack and we will try to address the issue as best we can.

Related People

Upcoming Events

Latest Opportunities