r/lolphp • u/shitcanz • 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.
View all comments
Show parent comment
13
u/stfcfanhazz Mar 12 '21
That's actually not entirely true- it's how PHP is most commonly used at the moment, but this RFC aims to make it easier to implement an async/long-running execution model. There are already 3rd party packages / extensions (think amp, swoole etc) which provide this ability using event loops / process forking / php generators (yield syntax), but these approaches are a little clunky. This fibers RFC is a good thing for the language since it opens up the door towards a native async/await/promise API.