Library for building an evented http server.
This component builds on top of the Socket component to implement HTTP. Here
are the main concepts:
- Server: Attaches itself to an instance of
React\Socket\ServerInterface, parses any incoming data as HTTP, emits arequestevent for each request. - Request: A
ReadableStreamwhich streams the request body and contains meta data which was parsed from the request header. - Response A
WritableStreamwhich streams the response body. You can set the status code and response headers via thewriteHead()method.
This is an HTTP server which responds with Hello World to every request.
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket);
$http->on('request', function ($request, $response) {
$response->writeHead(200, array('Content-Type' => 'text/plain'));
$response->end("Hello World!\n");
});
$socket->listen(1337);
$loop->run();See also the examples.
The recommended way to install this library is through Composer. New to Composer?
This will install the latest supported version:
$ composer require react/http:^0.4.3More details about version upgrades can be found in the CHANGELOG.
To run the test suite, you first need to clone this repo and then install all dependencies through Composer:
$ composer installTo run the test suite, go to the project root and run:
$ php vendor/bin/phpunitMIT, see LICENSE file.
