On Sat, Dec 23, 2023, at 2:34 PM, Kévin Dunglas wrote:
> Hello and Merry Christmas!
>
> One of the main features of FrankenPHP is its worker mode, which lets you
> keep a PHP application in memory to handle multiple HTTP requests.
>
> Worker modes are becoming increasingly popular in the PHP world. Symfony
> (Runtime Component), Laravel (Octane), and many projects based on these
> frameworks (API Platform, Sulu...) now support a worker mode.
>
> In addition to FrankenPHP, projects such as RoadRunner and Swoole provide
> engines supporting worker modes.
>
> According to benchmarks, worker modes can improve the performance of PHP
> applications by up to 15 times.
> In addition to FrankenPHP, which is basically a SAPI for Go's integrated
> web server, a new generation of SAPIs is currently under development.
> Several SAPIs written in Rust (including one by the RoadRunner team) are
> currently under development.
>
> These SAPIs, along with existing SAPIs, could benefit from a shared
> infrastructure to build worker modes.
>
>
>
> The FrankenPHP code is written and should be easy to move around in PHP
> itself, to enable other SAPIs to use it.
>
> In addition to sharing code, maintenance, performance optimization, etc.,
> the existence of a common infrastructure would standardize the way worker
> scripts are created and provide a high-level PHP API for writing worker
> scripts that work with all SAPIs that rely on this new feature.
>
> SAPIs will still have to handle fetching requests from the web server and
> pausing the worker to wait for new requests (in FrankenPHP, we use
> GoRoutines for this, in Rust or C, other primitives will have to be used),
> but almost everything else could be shared.
>
> For reference, here's the FrankenPHP code I propose to integrate into
> libphp: https://github.com/dunglas/frankenphp/blob/main/frankenphp.c#L245
>
> The public API is documented here:
> https://frankenphp.dev/docs/worker/#custom-apps
>
> I'd like to hear what the community thinks about this. Would you be
> interested in this functionality in PHP? Should I work on an RFC?
>
> If there's interest, I can work on a patch.
>
> Cheers,

In concept, I love this and would be ecstatic to see it happen.

In practice, I want to understand the implications for user-space code.  Does 
this mean FPM could be configured in a way to execute a file like that shown in 
the docs page above?  Or would it only work with third party SAPIs like 
FrankenPHP?  I assume the handler function would be differently named.  Is 
passing in super-globals the right/best way to handle each request, or would it 
be sensible to have some other abstraction there?  (Whether a formal request 
object a la PSR-7 or something else.)  To what extent would user-space code run 
this way have to think about concurrency, shared memory, persistent SQL 
connections, etc?  Does it have any implications for fiber-using async code?

Depending on the details, this could be like fibers but for 3rd party SAPIs 
(something about 4 people in the world actually care about directly, everyone 
else just uses Revolt, Amp, or React, but mostly it doesn't get used), or 
completely changing the way 90% of the market runs PHP, which means frameworks 
will likely adapt to use that model primarily or exclusively (ie, less of a 
need for a "compile" step as a generated container or dispatcher is just held 
in memory automatically already).  The latter sounds exciting to me, but I'm 
not sure which is your intent, so I don't know if I'm going too far with it. :-)

Please advise on what the implications would be for the non-SAPI-developing PHP 
devs out there.

--Larry Garfield

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

Reply via email to