Http Server ⋅ Introduction
Amp’s HTTP server is a non-blocking HTTP/1.1 and HTTP/2 application server written in PHP. This means that there’s no Apache or Nginx required to serve PHP applications with it. Multiple requests can be served concurrently and the application bootstrapping only needs to happen once, not once for every request.
Installation
The server can be installed as a Composer dependency.
composer require amphp/http-server
Several advanced components are available in separate packages, such as a routing, static content and WebSocket component.
Examples
Several examples can be found in the ./examples
directory of the repository.
These can be executed as normal PHP scripts on the command line.
php examples/hello-world.php
You can then access the example server at http://localhost:1337/
in your browser.
Logging
The Server
uses a NullLogger
by default.
If you pass a Psr\Log\LoggerInterface
instance to its constructor, you’ll get helpful log messages.
Optionally you can use Options::withRequestLogContext()
to enable passing the Request
object to the logger in the $context
array. This is disabled by default.
Internally generated log messages of the
DEBUG
level are only generated ifzend.assertions
is set to1
. If it isn’t set to1
in your config, load the server withphp -d zend.assertions=1 examples/hello-world.php
.