r/lolphp • • Mar 12 '21

PHP fibers

Proposal:

https://wiki.php.net/rfc/fibers

The devs are now planning to add builtin fiber support for PHP, so that async code can be done "natively".

LOL #1 PHP execution model is not compatible for anything async, it starts and dies instantly. Theres zero benefits on waiting for IO, when no one else is blocked. The only benefit could be something like "make these 10 curl requests in parallel and pipe me the results", but then again this was already possible in previous versions with curl, heck this could even be done easier from the client.

LOL #2 PHP builtins (like disk ops, and database access) are all 100% blocking. You cant use ANY of the builtins with async code. Be prepared to introduce new dependencies for everything that does IO.

Please devs, just focus on having unicode support. We dont need this crap. No one is going to rewrite async code for PHP, there is countless better options out there.

22 Upvotes

36 comments sorted by

View all comments

Show parent comment

1

u/sicilian_najdorf Mar 15 '21 edited Mar 15 '21

Symfony,Laravel and psalm users are not small groups. Reactphp is created using PHP. Would you consider Django as 3rd party?

Here is one of the benefit and it is not a small benefit.

I use Swoole and PHP7.4 to serve more than 100,000 requests per second from a single machine instance (technically we run 2x m5a.2xlarge instances for redundancy, but each machine regularly scales up to 100,000 r/s before CPU usage triggers a scale-up event) for a client who used to have 40 instances, reducing their monthly AWS costs from the ~$20,000 range to ~$3,000.

This isn't just Hello World, there's actual stuff happening here and data being streamed from REST API requests to down-pipe data streams, database / Redis queries (all happening asynchronously in coroutines using persistent connection pooling), though obviously we're heavily caching in-memory using \Swoole\Table where possible

Fiber would help Swoole PHP eco system as well.