werkint / reactphp-http
Library for building an evented http server.
Installs: 1 429
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 82
pkg:composer/werkint/reactphp-http
Requires
- php: >=5.4.0
- evenement/evenement: ^2.0
- guzzlehttp/psr7: ^1.0
- react/socket: ^0.4
- react/stream: ^0.4
- dev-master
- v0.4.2
- v0.4.1
- v0.4.0
- 0.3.x-dev
- v0.3.0
- v0.2.6
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.1
- v0.1.0
- dev-pauseresume-fix
- dev-server-fix
- dev-headers-fix
- dev-fix-consistent-request-header-parser-error-events
- dev-ci-travis-test-against-7.1-and-no-more-hhvm-nightly
- dev-feature-file-object
- dev-streaming-multipart
- dev-WyriHaximus-php7-hhvm-travis
- dev-compat-guzzle-deps
This package is not auto-updated.
Last update: 2019-02-20 19:05:00 UTC
README
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.
Quickstart example
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.