Methods |
public
|
__construct(string $host, int $port, int $timeout = -1)
Parameters
$timeout |
The number of seconds to wait for a request, or an
integer less than 0 to wait indefinitely. May be overridden via
{@see listen()}.
|
|
#
|
public
|
getHost(): string
Get the hostname or IP address of the server
Get the hostname or IP address of the server
|
#
|
public
|
getPort(): int
Get the TCP port of the server
Get the TCP port of the server
|
#
|
public
|
getTimeout(): int
Get the number of seconds the server will wait for a request
Get the number of seconds the server will wait for a request
If an integer less than 0 is returned, the server will wait
indefinitely.
|
#
|
public
|
hasProxy(): bool
Check if the server is configured to run behind a proxy server
Check if the server is configured to run behind a proxy server
|
#
|
public
|
getProxyHost(): string
Get the hostname or IP address of the proxy server
Get the hostname or IP address of the proxy server
Throws
LogicException |
if the server is not configured to run behind a
proxy server.
|
|
#
|
public
|
getProxyPort(): int
Get the TCP port of the proxy server
Get the TCP port of the proxy server
Throws
LogicException |
if the server is not configured to run behind a
proxy server.
|
|
#
|
public
|
proxyHasTls(): bool
Check if the proxy server uses TLS
Check if the proxy server uses TLS
Throws
LogicException |
if the server is not configured to run behind a
proxy server.
|
|
#
|
public
|
getProxyPath(): string
Get the path at which the server can be reached via the proxy server
Get the path at which the server can be reached via the proxy server
Throws
LogicException |
if the server is not configured to run behind a
proxy server.
|
|
#
|
public
|
withProxy(string $host, int $port, ?bool $hasTls = null, string $path = ''): static
Get an instance configured to run behind a proxy server
Get an instance configured to run behind a proxy server
Returns a server that listens at the same host and port, but refers to
itself in client-facing URIs as:
http[s]://<proxy_host>[:<proxy_port>][<proxy_path>]
|
#
|
public
|
withoutProxy(): static
Get an instance configured to run without a proxy server
Get an instance configured to run without a proxy server
|
#
|
public
|
getUri(): Uri
Get the client-facing URI of the server, with no trailing slash
Get the client-facing URI of the server, with no trailing slash
Call this method after {@see start()} if using dynamic port allocation.
|
#
|
public
|
isRunning(): bool
Check if the server is running
Check if the server is running
|
#
|
public
|
getLocalIpAddress(): string
Get the IP address to which the server is bound
Get the IP address to which the server is bound
Throws
|
#
|
public
|
getLocalPort(): int
Get the TCP port on which the server is listening
Get the TCP port on which the server is listening
Throws
|
#
|
public
|
start(): $this
Start the server
|
#
|
public
|
stop(): $this
Stop the server if it is running
Stop the server if it is running
|
#
|
public
|
listen<TReturn>(
callable(ServerRequestInterface $request): ServerResponse<TReturn> $listener,
int<-1, max> $limit = -1,
bool $catchBadRequests = true,
int|null $timeout = null,
bool $strict = false,
): TReturn|null
Wait for a request and provide the response returned by a listener
Wait for a request and provide the response returned by a listener
If the listener returns a response with a return value, the server stops
listening for requests, ignoring $limit if given, and returns the value
to the caller.
Parameters
$limit |
If -1 (the default), listen for requests
indefinitely. Otherwise, listen until $limit requests have been
received before returning null .
|
$catchBadRequests |
If false , throw the underlying exception
when an invalid request is rejected.
|
$timeout |
The number of seconds to wait for a request, an
integer less than 0 to wait indefinitely, or null (the default) to
use the server's default timeout.
|
$strict |
If true , strict [RFC9112] compliance is enforced.
|
Throws
|
#
|