phasync
Request handlers / ServerInterface

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#

MethodDescription
listenOpen the listener.
runAccept and serve connections until drained.
drainStop 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#

Example 1
$server->listen();                    // throws when the address can't be bound
phasync::run($server->run(...));      // returns once drain() was called and every connection ended

See also#

  • ClientRequestOne HTTP exchange with a client: the request to read, and the response to write. The application's RequestHandler is called once for each, and may keep it for as long as it likes (an event stream, a long download) by simply not returning.