Documentation

Server
in package

Built-in, completely pure HTTP server. It can work both in synchronous and asynchronous mode. Request processing is entirely up to you.

Table of Contents

$DataReadTimeout  : int
$MaxRequestLength  : int
__construct()  : mixed
Server constructor.
GetBytesReceived()  : float
GetBytesSent()  : float
GetUnsentResponses()  : array<string|int, Response>
Returns the array of unclosed requests (to be more precise, unsent responses).
On()  : void
Subscribe to event
Shutdown()  : void
Shutdown server
Start()  : void
Run server

Properties

$DataReadTimeout

public int $DataReadTimeout = 5

Timeout of data reading when connection accepted

$MaxRequestLength

public int $MaxRequestLength = 8192

The max length of request. If this length exceeded, the request will be closed immediately. Set -1 for no limit (on current version may work incorrectly).

Methods

__construct()

Server constructor.

public __construct([string $address = "0.0.0.0" ][, int $port = 8080 ]) : mixed
Parameters
$address : string = "0.0.0.0"

Listening IP-address. Pass "0.0.0.0" to use all available interfaces

$port : int = 8080

Port

Return values
mixed

GetBytesReceived()

public GetBytesReceived() : float
Return values
float

Count of received bytes

GetBytesSent()

public GetBytesSent() : float
Return values
float

Count of sent bytes

GetUnsentResponses()

Returns the array of unclosed requests (to be more precise, unsent responses).

public GetUnsentResponses() : array<string|int, Response>
Return values
array<string|int, Response>

On()

Subscribe to event

public On(ServerEvents $event, callable $callback) : void

Supported events:

  • start - triggers when server was started. Signature: function(HttpServer\Server $server) : void
  • shutdown - triggers when server was shutdown. Signature: function(HttpServer\Server $server) : void
  • request - triggers when request was received. Signature: function(HttpServer\Request $request, HttpServer\Response $response, HttpServer\Server $server) : void
  • throwable - triggers on uncaught exception while proceeding request. Signature: function(HttpServer\Request $request, HttpServer\Response $response, Throwable $throwable, HttpServer\Server $server) : void`
Parameters
$event : ServerEvents
$callback : callable
Tags
throws
UnknownEventException
Return values
void

Shutdown()

Shutdown server

public Shutdown() : void
Return values
void

Start()

Run server

public Start([bool $async = false ]) : void
Parameters
$async : bool = false

If you set TRUE, server will be started in background mode. It means this method won't block code execution after this method

Tags
throws
ServerStartException
Return values
void

Search results