Created
October 26, 2012 18:51
-
-
Save cs278/3960672 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__.'/vendor/autoload.php'; | |
$loop = React\EventLoop\Factory::create(); | |
$socket = new React\Socket\Server($loop); | |
// Create a blob of data for testing | |
$data = ''; | |
for ($i = 1; $i <= 8; $i++) $data .= $i.str_repeat("\0", 1022)."\n"; | |
file_put_contents('data', $data); | |
$http = new React\Http\Server($socket); | |
$http->on('request', function (React\Http\Request $request, React\Http\Response $response) use ($loop) { | |
$url = 'data'; | |
$readStream = fopen($url, 'r'); | |
stream_set_blocking($readStream, 0); | |
$read = new React\Stream\Stream($readStream, $loop); | |
$response->writeHead(200, array('Content-Type' => 'text/plain')); | |
$read->pipe($response); | |
}); | |
$socket->listen(1337); | |
$loop->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment