GSoC 2014: WebSockets in WordPress

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

GSoC 2014: WebSockets in WordPress

Atanas Penchev

For quite some time since I started following the development of React and
Ratchet, I have been intrigued by the idea of using WebSockets together
with WordPress. Although on Apache installations a WebSocket server would
still require running an additional process, it provides many potential
benefits for both users and developers.

By using Ratchet, I plan to write a WebSocket API which could be used for
plugin development. It should ease the creation of real-time solutions,
like new comments and posts notifications, chat systems and live updates of
the site's components (for example, automatically displaying new content to
all users as soon as it becomes available without a browser refresh).

Besides the use of WebSockets, I am also thinking of using the React server
for serving request, which could provide a significant performance boost,
as mentioned in this post:

During the time working in a small company, I had to go through WordPress
theme and plugin development. Also, I had developed several applications
with Node.js/PHP + React and WebSockets and I believe it would be a great
experience combining my skills while improving such a successful project.

What are your thoughts on the idea? Any feedback would be useful. :)
wp-hackers mailing list
[hidden email]
Reply | Threaded
Open this post in threaded view

Re: GSoC 2014: WebSockets in WordPress

Bryan Petty
On Tue, Mar 18, 2014 at 11:50 AM, Atanas Penchev <[hidden email]> wrote:
> Besides the use of WebSockets, I am also thinking of using the React server
> for serving request, which could provide a significant performance boost,
> as mentioned in this post:

That article is pretty nice, and even points out some of the downsides
and technical issues involved, which are also very critical to
WordPress as well, so let me just briefly cover them to the best of my

1. While Symfony contains a Request/Response system that he talks
about in that article, in WordPress, it's much worse. A bunch of core
functions and plugins directly access superglobals for $_REQUEST and
$_SERVER values. As pointed out, those are entirely unreliable in the
environment of asynchronous requests.
2. Also a problem for asynchronous requests: hooks. These are bound by
global context, meaning hooks would have no idea what request/client
was being served, which DB resource to use (what if we were in a
transaction?), or what output stream to echo out to. ReactPHP was
built with MVC architectures and template engines in mind - neither of
which we use. And as far as backwards compatibility goes, there's
likely nothing we can do to handle any of those while staying
compatible with existing plugins.

So, even if we managed to work our way around blocking IO calls (PDO,
DNS, etc), this means that we still can't use async requests. It's
best to just forget about it (especially for GSoC). That doesn't mean
we can't still use WebSockets or React, it just means that we can't
use async/promise. Of course, this defeats most of the performance
gains React likes to gloat about, but it would still cut back on PHP

Unfortunately, without async, this introduces another problem. It
means we will be performing blocking calls (which was likely going to
happen anyway with PDO). And since we'll be blocking, we won't want
one user blocking requests from another user, so we would likely want
to avoid re-using connections across sessions. We probably already
want to anyway since authorization checks also rely on request/session
identity stored in global values. This is a difficult task which I'm
not sure has a solution with a fixed server pool configuration. It's
not going to scale with 50+ concurrent admin users (including authors
writing posts) leaving heartbeat WebSockets open to individual PHP
processes on different ports.

Maybe I'm wrong about some of this, and hopefully someone else on the
list can correct me or point out other solutions I'm not aware of to
these problems. But this is all probably worth some discussion before
any students jump head-first into this for GSoC.

Bryan Petty
wp-hackers mailing list
[hidden email]