On 30 December 2023 19:48:39 GMT, Larry Garfield <la...@garfieldtech.com> wrote:
>The Franken-model is closer to how PHP-FPM works today, which means that is 
>easier to port existing code to, especially existing code that has lots of 
>globals or hidden globals.  (Eg, Laravel.)  That may or may not make it the 
>better model overall, I don't know, but it's the more-similar model.

That's why I said earlier that it provides better backwards compatibility - 
existing code which directly uses PHP's current global state can more easily be 
run in a worker which populates that global state.

However, the benefit is marginal, for two reasons. Firstly, because in practice 
a lot of applications avoid touching the global state outside of some request 
bootstrapping code anyway. The FrankenPHP example code and Laravel Octane both 
demonstrate this.

Secondly, because in an environment that handles a single request at a time, 
the reverse is also possible: if the server passes request information directly 
to a callback, that callback can populate the superglobals as appropriate. The 
only caveat I can think of is input streams, since userland code can't reset 
and populate php://input, or repoint STDOUT.

On the other hand, as soon as you have any form of concurrency, the two models 
are not interchangeable - it would make no sense for an asynchronous callback 
to read from or write to global state.

And that's what I meant about FrankenPHP's API having poor forward 
compatibility - if you standardise on an API that populates global state, you 
close off any possibility of using that API in a concurrent environment. If you 
instead standardise on callbacks which hold request and response information in 
their own scope, you don't close anything off.

If anything, calling this "forwards compatibility" is overly generous: the OP 
gave Swoole as an example of an existing worker environment, but I can't see 
any way that Swoole could implement an API that communicated request and 
response information via global state.

Regards,

-- 
Rowan Tommins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to