Created
June 17, 2014 20:49
-
-
Save icambridge/d8c1ea63cce6733bc5d5 to your computer and use it in GitHub Desktop.
An example of how to get the request body
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_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(); |
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
output to a client
"Hello World"