react 0,2,7,0,1,6,0,3 travis-ci Packagist phpunit

Event-driven, non-blocking I/O with PHP, formerly known as "Nuclear Reactor written in PHP"


Event-driven, non-blocking I/O with PHP.

Build Status

Notice - (May 25th, 2014)

As of 2014-05-25 we have reversed roles of this and the component repositories. Instead of reactphp/react being the master code repository it is now the sum of React’s parts. All PRs should be made against their corresponding repository found in /reactphp. All existing PRs will be evaluated and work will be done with the submitter to merge it into the proper component.


The recommended way to install React is through composer. Type the following command in your shell environment:

php ~/composer.phar require react/react

What is it?

React is a low-level library for event-driven programming in PHP. At its core is an event loop, on top of which it provides low-level utilities, such as: Streams abstraction, async dns resolver, network client/server, http client/server, interaction with processes. Third-party libraries can use these components to create async network clients/servers and more.

The event loop is based on the reactor pattern (hence the name) and strongly inspired by libraries such as EventMachine (Ruby), Twisted (Python) and Node.js (V8).

Design goals

  • Usable with a bare minimum of PHP extensions, add more extensions to get better performance.
  • Provide a standalone event-loop component that can be re-used by other libraries.
  • Decouple parts so they can be replaced by alternate implementations.

React is non-blocking by default. Use workers for blocking I/O.

High-level abstractions

There are two main abstractions that make dealing with control flow a lot more manageable.

  • Stream: A stream represents an I/O source (ReadableStream) or destination (WritableStream). These can be used to model pipes, similar to a unix pipe that is composed of processes. Streams represent very large values as chunks.

  • Promise: A promise represents an eventual return value. Promises can be composed and are a lot easier to deal with than traditional CPS callback spaghetti and allow for almost sane error handling. Promises represent the computation for producing single values.

You should use these abstractions whenever you can.


Here is an example of a simple HTTP server listening on port 1337:


require 'vendor/autoload.php';

$i = 0;

$app = function ($request, $response) use (&$i) {

    $text = "This is request number $i.\n";
    $headers = array('Content-Type' => 'text/plain');

    $response->writeHead(200, $headers);

$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket);

$http->on('request', $app);



Superficial documentation can be found in the README files of the individual components. See vendor/react/*/src/


Check out #reactphp on Also follow @reactphp on twitter.


To run the test suite, you need install the dependencies via composer, then run PHPUnit.

$ composer install
$ phpunit



Top Contributors

igorw cboden arnaud-lb jmalloc nrk clue jmikola jsor WyriHaximus cameronjacobson kertz robinvdvleuten romainneutron e3betht beaucollins cgcai elliot hannesvdvreken whatthejeff h4cc lt pborreli Sgoettschkes Irvyne yuya-takeyama drak3


package version
php >=5.4.0
react/cache 0.4.*
react/child-process 0.4.*
react/dns 0.4.*
react/event-loop 0.4.*
react/http-client 0.4.*
react/http 0.4.*
react/promise ~2.1
react/socket-client ^0.5.3
react/socket 0.4.*
react/stream 0.4.*
dev phpunit/phpunit ~4.0
clue/block-react ^1.1
clue/stream-filter ^1.3


-   v0.4.2 zip tar
-   v0.4.1 zip tar
-   v0.4.0 zip tar
-   v0.3.4 zip tar
-   v0.3.3 zip tar
-   v0.3.2 zip tar
-   v0.3.1 zip tar
-   v0.3.0 zip tar
-   v0.2.7 zip tar
-   v0.2.6 zip tar
-   v0.2.5 zip tar
-   v0.2.4 zip tar
-   v0.2.3 zip tar
-   v0.2.2 zip tar
-   v0.2.1 zip tar
-   v0.2.0 zip tar
-   v0.1.1 zip tar
-   v0.1.0 zip tar