Skip to content

Instantly share code, notes, and snippets.

@romainneutron
Created January 3, 2013 17:28
Show Gist options
  • Save romainneutron/4445153 to your computer and use it in GitHub Desktop.
Save romainneutron/4445153 to your computer and use it in GitHub Desktop.
<?php
$i = 0;
$app = function ($request, $response) use (&$i) {
$request->on('end', function() use ($response, &$i) {
$i++;
$text = "This is request number $i.\n";
$headers = array('Content-Type' => 'text/plain');
$response->writeHead(200, $headers);
$response->end($text);
});
};
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket);
$http->on('request', $app);
$socket->listen(1337);
$loop->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment