Hey,

On 22.11.2026 17:04:54, Tim Düsterhus wrote:
Hi

On 11/9/26 15:24, Kévin Dunglas wrote:
Following the recent pre-RFC discussion
(https://news-web.php.net/php.internals/132960), I would like to open
the discussion on the "Request lifecycle hooks for SAPIs with a worker
mode" RFC:
https://wiki.php.net/rfc/request_lifecycle_hooks


Thank you for your RFC. I have a few remarks:

I like the premise of the RFC as well!


2. In the “Engine Functions” section:

Releasing the request body takes two small changes: php://input streams hold a reference to the body, and freeing the body, for instance when the script closes it, clears SG(request_info).request_body.

From this statement it is not clear to me what happens when a script holds an open `php://input` stream resource across a REND + RBEGIN boundary. Will the existing resource return EOF after that? Will it silently hold data from the next request? This should be spelled out more explicitly.

3. I wonder if the initial “userland bootstrap” request should also get a RBEGIN call directly after RINIT. Is there a reason this is not done? This would also resolve the point that Florian mentioned. From what I understand, extensions would currently need to duplicate some of the set-up logic between RINIT and RBEGIN (or call their own RBEGIN from RINIT).

For `session.auto_start` in particular it would be quite nice to move that into `RBEGIN` only. If I remember correctly, `php -l` creates sessions if `session.auto_start` is enabled. This is at minimum surprising. Similarly for Tideways I need to jump through some hoops to exclude requests that don't actually execute code (including preloading in FPM) to prevent empty traces from being created for them. If I could switch to RBEGIN this would make things easier, I would hope.

Is there actually the one model which encapsulates all needs? If you have RINIT+RBEGIN -> (REND+??)RBEGIN -> [REND -> RBEGIN] -> REND(+RBEGIN??) -> REND -> RSHUDTOWN, how am I going to know that the initial RBEGIN is handling an user request? What happens to state which is supposed to be request-specific, but at the same time needs to somehow persist from start to end of execution.

It's all a bit odd, and don't feel like there is an actual good solution for this without nesting. And the Scope RFC would actually properly solve it. With the Scope RFC you also don't need a RINIT -> REND -> [RBEGIN -> REND] -> RBEGIN -> RSHUTDOWN, but it properly nests. All you need is "scope start, scope end" then. And we could have RINIT -> (main) Scope start -> [nested scope start, end interleaved possibly] -> (main) scope end -> RSHUTDOWN.


One further thing [I know it conflates a bit with scope RFC discussion] I'm concerned about, in the scope RFC is "when is it ready". For the main scope it's not an issue, but when a scope is created, it is have its parents contents. But we want to check the superglobals, whatever, for e.g. ext/session with auto_start to consume, or stuff like datadog or tideways which are interested in the request data as well. Also, not every scope (as proposed in the scope RFC) is something you'd necessarily consider a "request" (e.g. you might create a scope to isolate some code which modifies superglobals, output buffers, whatever, but without actually it being a new request).

So, if the scope RFC had a mechanism to initialize the scope, between creation, and processing, hooks like a "scope ready" could exist properly in that space.


Embracing scopes here also solves the 2. point with SG(request_info).request_body etc. which scopes would simply clearly backup / refcount.


4. I don't think the RFC Impact and BC incompatible changes sections are fully accurate as written. If *other* extensions (including built-in extensions) make use of the new hooks and move code from RINIT to RBEGIN than extensions that remain RINIT-only might miss some information from the structures that they've previously relied on. Similarly if extensions rely on RBEGIN to work correctly, they will will break for SAPIs that don't call RBEGIN.

Yeah, I think if we implement this RFC as is, the result will be a bit chaotic in the gritty details; I only think proper nested scoping can solve this cleanly.

Best regards
Tim Düsterhus


To summarize: I think you (Kévin) should work with the scope RFC author to make sure that proper hooking into scope events exists rather than this proposal, which has, in my opinion, unsolvable issues. I don't think a flat model (one which considers the part before frankenphp_handle_request and after it two distinct parts of execution) will work out nicely. It would be a story of manually backing state up, trying to figure out whether a RBEGIN hook is now on the main level or actually a worker processing stuff etc.


Thanks,

Bob

Reply via email to