amphp / http-server
A non-blocking HTTP application server for PHP based on Amp.
Fund package maintenance!
amphp
Installs: 987 143
Dependents: 61
Suggesters: 1
Security: 0
Stars: 1 239
Watchers: 60
Forks: 105
Open Issues: 4
Requires
- php: >=8.1
- amphp/amp: ^3
- amphp/byte-stream: ^2
- amphp/cache: ^2
- amphp/hpack: ^3
- amphp/http: ^2
- amphp/pipeline: ^1
- amphp/socket: ^2.1
- amphp/sync: ^2
- league/uri: ^6
- league/uri-interfaces: ^2.3
- psr/http-message: ^1
- psr/log: ^1|^2|^3
- revolt/event-loop: ^1
Requires (Dev)
- amphp/http-client: ^5
- amphp/log: ^2
- amphp/php-cs-fixer-config: ^2
- amphp/phpunit-util: ^3
- league/uri-components: ^2
- monolog/monolog: ^3
- phpunit/phpunit: ^9
- psalm/phar: ^5.4
Suggests
- ext-zlib: Allows GZip compression of response bodies
- 3.x-dev
- v3.0.0-beta.8
- v3.0.0-beta.7
- v3.0.0-beta.6
- v3.0.0-beta.5
- v3.0.0-beta.4
- v3.0.0-beta.3
- v3.0.0-beta.2
- v3.0.0-beta.1
- 2.x-dev
- v2.1.8
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.1
- v2.0.0
- v2.0.0-rc4
- v2.0.0-rc3
- v2.0.0-rc2
- v2.0.0-rc1
- v1.x-dev
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.1
- v1.0.0
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.4
- v0.7.3
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.0
- v0.4.7
- v0.4.6
- v0.4.5
- v0.4.4
- v0.4.3
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.0
- v0.2.0
- v0.1.0
- dev-3.x-forwarded
- dev-h2-uploads
- dev-priority
This package is auto-updated.
Last update: 2023-06-03 16:00:09 UTC
README
This package provides a non-blocking HTTP/1.1 and HTTP/2 application server written in PHP based on Amp. Several features are provided in separate packages, such as the WebSocket component.
The packages was previously named amphp/aerys
, but has been renamed to be easier to remember, as many people were having issues with the old name.
Features
- Static file serving
- WebSockets
- Dynamic app endpoint routing
- Request body parser
- Sessions
- Full TLS support
- Customizable GZIP compression
- HTTP/2.0 support
- Middleware hooks
- CORS (3rd party)
Requirements
- PHP 7
Installation
composer require amphp/http-server
Documentation
Example
<?php use Amp\Http\Server\RequestHandler\ClosureRequestHandler; use Amp\Http\Server\SocketHttpServer; use Amp\Http\Server\Request; use Amp\Http\Server\Response; use Amp\Http\Status; use Amp\Socket\Server; use Psr\Log\NullLogger; // Run this script, then visit http://localhost:1337/ in your browser. Amp\Loop::run(function () { $sockets = [ Server::listen("0.0.0.0:1337"), Server::listen("[::]:1337"), ]; $server = new SocketHttpServer($sockets, new ClosureRequestHandler(function (Request $request) { return new Response(Status::OK, [ "content-type" => "text/plain; charset=utf-8" ], "Hello, World!"); }), new NullLogger); yield $server->start(); // Stop the server gracefully when SIGINT is received. // This is technically optional, but it is best to call Server::stop(). Amp\Loop::onSignal(SIGINT, function (string $watcherId) use ($server) { Amp\Loop::cancel($watcherId); yield $server->stop(); }); });
php example.php
Contributing
Please read CONTRIBUTING.md
for details on our code of conduct, and the process for submitting pull requests to us.
Security
If you discover any security related issues, please email contact@amphp.org
instead of using the issue tracker.
License
The MIT License (MIT). Please see LICENSE for more information.