ClassGo
HTTP\Server
class HTTP\Server {
- public function __construct(string $addr, mixed $handler, int ...$workers);
- public function addr(): string;
- public function close(): void;
- public function listen(): string;
- public function shutdown(): void;
- public function wait(): void;
}
Description
HTTP\Server listens on $addr and answers through $handler, an HTTP\Mux or anything else that answers a request; $workers bounds how many requests the server answers at once and defaults to the number of cores. $server->listen() binds and returns the address, $server->wait() blocks until the script runs out of time, and $server->shutdown() stops it, letting what is in flight finish.
HTTP\Server is a class phpscript declares.
$object = new HTTP\Server($addr, $handler, $workers);
Methods
public function addr(): string-
addr answers the address the server bound, empty until it has listened.
The go method
Addr. public function close(): void-
close stops the server at once, dropping everything in flight, and returns the error shutdown() swallows. To let a request in flight finish, a script calls shutdown().
The go method
Close. public function listen(): string-
listen binds the address and starts answering, and returns the address it bound. It does not block: the script goes on, and calls wait() when its work completes.
The go method
Listen. public function shutdown(): void-
shutdown is http.Server.Shutdown with a second of grace, then Close.
It returns no value and throws no error: a script writes it into a register_shutdown_function callback, which runs when the script has already ended and has nowhere to put a failure. Calling it twice, or without having listened, is not an error either.
The go method
Shutdown. public function wait(): void-
wait blocks until the script runs out of time or its client goes away.
The go method
Wait.
Binding
- The go type
github.com/titpetric/phpscript/stdlib/http.Server. - Registered by the package
github.com/titpetric/phpscript/stdlib/http. - Built on
net/http.Server. - Satisfies
io.Closer.