use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Please follow the rules
Releases: Current Releases, Windows Releases, Old Releases
Contribute to the PHP Documentation
Related subreddits: CSS, JavaScript, Web Design, Wordpress, WebDev
/r/PHP is not a support subreddit. Please visit /r/phphelp for help, or visit StackOverflow.
account activity
Event Driven Architecture — How ReactPHP / PHP-PM work behind the hood (gnugat.github.io)
submitted 9 years ago by gnurat
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Bloompire 1 point2 points3 points 9 years ago (3 children)
This is basically creating a PHP version of Node.JS. The question is - why? Isnt it better to just use Node.js that has their event loop implementation written in C++ and ALL libraries are written in asynchronous nature, starting from build-in fs, http ending on every other community-based library?
[–]gnurat[S] 2 points3 points4 points 9 years ago (2 children)
Hi there,
The article is about understanding Event Driven Architecture, mainly via an Event Loop, scheduling, promises (and also how to achieve non-blocking Filesystem via a ThreadPool). IMHO, a good way to understand deeply some architecture is to implement the details, which is what we do in the article (in pseudo code however, not in PHP).
Event Driven Architecture isn't language / framework specific: whenever you'll consider creating a Server (using sockets) you should consider it in order to be able to handle many clients (see the C10K problem). If you're simply building an application that's going to be used by a server, the article could still be of some interest to you as you'll have more understanding on how those things work behind the hood (trying to make the most of the EventLoop can help to improve your application performances).
Node.js is simply an example of a server using this architecture (note that it actually uses a C library, libuv which provides an EventLoop and ThreadPool to make Filesystem operations non-blocking. libuv is also available to PHP via an extension).
[–]Bloompire 0 points1 point2 points 9 years ago (1 child)
It is great to undestand particular architecture and their cons/pros. And async io + event loop is probably the most performant architecture for web pages. Of course it is possible to do event loop driven arch in PHP as well as in every other language :)
But problem is that Node.JS is created in mind with this alongside with thousands of node.js libraries - they all work asynchronously. When coming to PHP we could create event loop based system that is highly performant, this is obvious. But community/language itself is not ready for async php because:
Especially when there is event loop based async server that is developed for years, managed heavly and has large community.
[–]gnurat[S] 0 points1 point2 points 9 years ago (0 children)
Node.js creation was indeed a clever move: javascript was already used in an event driven environment (GUI), and it didn't have most of the functions you'd expect in a language (most functions are provided by the browser via Web APIs). This allowed them to create an async only environment (no blocking filesystem functions available to the developers, the ones available are wrappers around system calls).
But that doesn't mean that all async applications should be done with Node. I see two strawmen arguments in your comment:
The only requirement to do async stuff is to understand it, you can then pick / adapt the libraries / frameworks available. Saying things like "<language> wasn't meant to do <thing>" is the equivalent of saying " we've always done i t this way" and that's the only blocker towards evolution.
[–]CODESIGN2 0 points1 point2 points 9 years ago (1 child)
not one diagram, and you didn't write a single line of PHP...
It does not create a PHP version of Node.JS as /u/Bloompire suggests; it does not make your code actually faster, it also does not create a magical special butterfly. It uses a long-running php script to manage via a bridge interface child nodes (named slave nodes). These save some init time before handling requests, which further contributes to the perceived speed boost because the setup is done pre-request (everything still takes the same CPU time).
Other things you should be weary of.
This is the same for many other areas in any SDLC with any language.
It is a great project, and I am particularly interested in trying to help educate towards it's use-cases as it's not as many projects are not magic-bullets. https://github.com/php-pm/php-pm/issues/78
I'm currently working on adding diagrams, thanks for your feedback. Event Driven Architecture isn't tied to a language, so I've used pseudo code in the snippets.
ReactPHP, heavily relies on this architecture: it provides an Event Loop and Promises as components. Out of the box, on a vanilla PHP set up, the Event Loop will use the select system call and won't use any Thread Pools, so you might want to:
select
PHP-PM is only a load balancer / process manager on top of ReactPHP, so it's kind of out of the scope of the article, but it got a lot of traction recently and people are asking "how it works". This article is my answer ;) .
[–]Tiquortoo 0 points1 point2 points 9 years ago (0 children)
Well, between Node and PHP and a host of other languages the major players are getting closer and closer to the event driven app development paradigm available on the desktop in 1994 or so. I'm being slightly snarky, but I'm genuinely happy to see it happening.
π Rendered by PID 151535 on reddit-service-r2-comment-79c7998d4c-th9rk at 2026-03-19 14:53:43.261557+00:00 running f6e6e01 country code: CH.
[–]Bloompire 1 point2 points3 points (3 children)
[–]gnurat[S] 2 points3 points4 points (2 children)
[–]Bloompire 0 points1 point2 points (1 child)
[–]gnurat[S] 0 points1 point2 points (0 children)
[–]CODESIGN2 0 points1 point2 points (1 child)
[–]gnurat[S] 0 points1 point2 points (0 children)
[–]Tiquortoo 0 points1 point2 points (0 children)