Skip to content

Instantly share code, notes, and snippets.

@icambridge
Created June 17, 2014 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icambridge/d8c1ea63cce6733bc5d5 to your computer and use it in GitHub Desktop.
Save icambridge/d8c1ea63cce6733bc5d5 to your computer and use it in GitHub Desktop.
An example of how to get the request body
<?php
require_once __DIR__ . "/../vendor/autoload.php";
$app = function (\React\Http\Request $request, \React\Http\Response $response) {
$data = new \React\Stream\BufferedSink();
$request->pipe($data);
$data->promise()->then(function($data) use ($request, $response) {
echo $data.PHP_EOL;
$response->end("Bye World\n". PHP_EOL);
} );
$response->writeHead(200, array('Content-Type' => 'text/plain'));
$response->end("Hello World\n". PHP_EOL);
print "End".PHP_EOL;
};
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket, $loop);
$http->on('request', $app);
echo "Server running at http://127.0.0.1:1337\n";
$socket->listen(1337);
$loop->run();
@icambridge
Copy link
Author

output to a client

"Hello World"

@icambridge
Copy link
Author

Noticed issue, using end instead of write.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment