Write PHP non blocking applications Write PHP non blocking applications python python

Write PHP non blocking applications


Writing non blocking applications in php is possible, but it's probably not the best environment to do so, as it wasn't created keeping that in mind! You get a pretty decent control over your child processes using the process control library PCNTL but it obviously won't ever offer you same ease of use that other environments can give you!

I don't know python very well but personally I'd recommended you go with nodejs! It's a fairly new technology, that's true, but everything is non blocking there and it's meant to be that way! Basically what you have is a single thread (which you can extend however you want in this news versions) and literally everything (except you tell it to do differently) is going to be event-driven, leaving space to proceed on the process queue as expected!

Nodejs is really easy to learn, if you ever stumbled upon web applications, you know javascript anyways! it is still not hugely documented, but there are many ready to use modules you can download and use straight away!


As far as i known, there are several libraries available to build non-blocking applications.

  1. Skyray, a networking library for PHP writen in C http://github.com/bixuehujin/skyray
  2. reactphp, as mentioned above written in pure PHP
  3. swoole, https://github.com/swoole/swoole-src
  4. phpdaemon, https://github.com/kakserpom/phpdaemon

BTW: i am the author of Skyray, and one of the developer of swoole.


I haven't looked at pushpin yet, but I'm writing this answer to point to another framework that supports non-blocking applications in PHP:

React http://reactphp.org/

It supports binding a server to HTTP, or WebSocket and can be used with webserver software such as Nginx by forwarding (using proxy_pass) requests to it over HTTP. You can even use HTTPS in the webserver and forward that non-encrypted. (SSL support in React is lacking.)

There doesn't appear to be FastCGI or UWSGI support yet, at least not in the upstream project.

The style is similar to writing node.js, you attach PHP 5.3+ closures to events, and it uses the non-blocking sockets transparently underneath. There are good examples on that website, so I won't repeat them here since you didn't ask for a use case specifically.

UPDATED: I just looked at the pushpin website and it's not a framework or tool for writing non-blocking PHP applications as requested in the question title. It does seem like it would be useful as part of a solution though.