Interface
ServerInterface
A protocol server, such as HTTP/1.1 (--http).
Introduction#
It turns what arrives on its listener into ClientRequests and gives each to the
application's RequestHandler. A worker calls listen(), then
run() inside phasync::run(), and drain() when it is to stop.
Class synopsis#
interface ServerInterface {
/* Methods */
public ServerInterface::listen(): void
public ServerInterface::run(): void
public ServerInterface::drain(bool $linger = false): void
}Methods#
| Method | Description |
|---|---|
listen | Open the listener. |
run | Accept and serve connections until drained. |
drain | Stop accepting; ServerInterface::run returns once every connection has ended. Meanwhile the worker stops the requests in flight with a WorkerStoppingException at their wait, and the server ends its protocol for each (a 503 for a response not yet begun). |
Examples#
$server->listen(); // throws when the address can't be bound
phasync::run($server->run(...)); // returns once drain() was called and every connection endedSee also#
ClientRequestOne HTTP exchange with a client: the request to read, and the response to write. The application'sRequestHandleris called once for each, and may keep it for as long as it likes (an event stream, a long download) by simply not returning.