On 5 January 2024 09:02:05 GMT, Robert Landers <landers.rob...@gmail.com> wrote:
> I don't think they are fundamentally incompatible. If we look at
>FrankenPHP's implementation, you pass a callback that gets called when
>there is a request.

No, you pass a callback which is called exactly once, for the next request. You 
have to implement your own loop if you want to handle multiple requests, which 
obviously isn't how it would work with an async event loop.

That was one of my suggested changes: move the loop into C, so that the API was 
"callback called for each request". This actually *adds* flexibility on the 
server end, to decide how often to call that callback, do so asynchronously, 
etc.



> Globals is how this works (atm)

It's how it works for native SAPIs. It's not, as far as I know, how any worker 
system other than FrankenPHP has implemented its API. Every other 
implementation I've seen, whether async or not, passes in some form of request 
data to the callback, with the exception of RoadRunner, which gives the data as 
a return value from a "get next request" function.

So, the second suggested change is to standardise on the most common pattern of 
passing parameters to a callback, rather than the unusual one of populating and 
clearing superglobals. As a bonus, this pattern works with both non-async and 
async workers.


> changing the signature of the callback is generally backwards compatible

This is true in the narrow sense that it won't cause any fatal errors. But if 
you write your application assuming that it will run in an environment where 
globals are populated for you, it will not run in an environment which no 
longer populates those globals.



>Changing the underlying implementation in php-src when there are
>native fibers/event loops probably won't even change anything (since
>that was exactly how they were designed).

Sounds great! So we don't need to wait to put that implementation in place then.



>But holding up the entire conversation ...

There is no reason whatsoever to hold anything up. The suggestion is not "don't 
implement any worker API until we have an async implementation", it's "a worker 
API sounds great, let's implement one that looks like this".

Yes, it might take slightly longer to define some new array structures, but 
we're talking about a few hours work to give us a much more flexible system, 
not weeks of complex engineering.

If the proposal is "copy some code from FrankenPHP into php-src, which nobody 
else will want to use", it's pointless; if it's "standardise an API with some 
enabling code", then *of course* we want to spend a bit of time designing that 
API.


Regards,

-- 
Rowan Tommins
[IMSoP]

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

Reply via email to