Re: [RFC] Request lifecycle hooks for SAPIs with a worker mode
| From: | Kévin Dunglas | Date: | Tue, 10 Nov 2026 13:26:21 +0000 |
| Subject: | Re: [RFC] Request lifecycle hooks for SAPIs with a worker mode | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-133058@lists.php.net to get a copy of this message | ||
Hi Florian,
Thanks for taking the time to read the RFC and review the patches.
Yes, it’s intended, and it’s already how FrankenPHP behaves today.
Because of how the engine works internally, the "dummy" request that
boots the worker script and the "logical" requests handled in the loop
don’t overlap: they run one after the other.
The full sequence in FrankenPHP is:
* RINIT ("dummy" request)
* userland bootstrap code
* main loop, frankenphp_handle_request() waits for a request (its
first call first runs REND to clean the request-specific state tied to
the "dummy" request):
* RBEGIN (logical HTTP request)
* callback
* REND (logical HTTP request)
* when the worker must stop, frankenphp_handle_request() calls
RBEGIN and returns false: this recreates a "dummy" request, because
the code after the loop can still write output, and
php_request_shutdown() needs an active request
* userland shutdown code
* RSHUTDOWN ("dummy" request)
For extensions, the rules are the same as today: what is set up in
RINIT or RBEGIN must be released in the next REND or RSHUTDOWN. A
debugger or a profiler will likely keep running the same code as today
in RSHUTDOWN, and an adapted version of it in the new REND. That’s by
design: existing extensions keep working unchanged, and a logical
request is now simply one that starts with RBEGIN and ends with REND.
Best,
Kévin