Hacker News new | ask | show | jobs
by exikyut 1523 days ago
PHP seriously needs an event loop. The Node model, where things that call into libuv to wait on servers and such prevent the script from exiting, is simple enough to implement and while mildly unintuitive to newcomers is still accessible thanks to Node's popularity.
3 comments

If anything the NodeJs model is trickier to scale because it requires discipline to never block the loop unnecessarily.

PHP/Go/C# one-thread-per-HTTP-request also requires less cognitive load where everything is synchronous by default. Also PHP's throw-away-everything after each request tolerates much more junior-code abuse.

Forgot to close a database connection or transaction? No problem, PHP will do that for you. Left a file open? Forgot to close a CURL handle? No worriers the janitor is coming to clean your mess at the end of the request.

With that said, PHP does have an event loop. See ReactPHP and Swoole. They existed for years and while they have their uses, they aren't going to overtake "standard" PHP execution model anytime soon partly because of the reasons above.

PHP has support for event loops, including libuv. See https://reactphp.org/ you can build performant websocket servers with this.
As long as from the programmer's perspective it's opt-in rather than opt-out—that is, "await" by default. That was a huge mistake for Node and will seemingly haunt it forever.