Skip to content

Instantly share code, notes, and snippets.

@igorw
Created June 24, 2012 14:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorw/2983440 to your computer and use it in GitHub Desktop.
Save igorw/2983440 to your computer and use it in GitHub Desktop.
<?php
require 'vendor/autoload.php';
$loop = new React\EventLoop\StreamSelectLoop();
$app = function ($request, $response) use ($loop) {
$response->writeHead(200, []);
$fh = fopen('http://localhost/', 'r');
$conn = new React\Socket\Connection($fh, $loop);
$loop->addReadStream($fh, [$conn, 'handleData']);
$buf = '';
$conn->on('data', function ($data) use (&$buf) {
$buf .= $data;
});
$conn->on('end', function () use (&$buf, $response) {
$response->end($buf);
});
};
$stack = new React\Espresso\Stack($app);
$stack['loop'] = $loop;
$stack->listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment