Menu
Reference
- Manticore\Ds
- Async
- Http
- Http\WebSocket
- Interfaces
- Handler
- Classes
- Connection
- ConnectionClosedException
- HandshakeException
- Hub
- Message
- Options
- Functions
- connect()
- handler()
- run()
- upgrade()
- Buffer
- Process
- Io\Poll
- Manticore\Sapi
- Ffi
Options
final class Options
Settings for a WebSocket connection, server or client side.
Every setting is a public property with a fluent setter of the same name that returns the same object, so options chain:
$o = (new Options())->protocols(['chat.v2'])->pingInterval(15.0)->compression(true);Durations are in seconds. An Options is passed to upgrade() on the server
and to connect() on the client; the same object may serve many connections.
Properties
maxMessageSize | int | Largest accepted message, in bytes, after reassembly and decompression. |
maxFrameSize | int | Largest accepted single frame payload, in bytes. |
pingInterval | float | Seconds of silence before a ping is sent; also the read timeout. |
pongTimeout | float | Seconds to wait for the answer to a keepalive ping before the connection is dropped (close code 1006). |
closeTimeout | float | Seconds to wait for the peer's Close frame after sending ours. |
connectTimeout | float | Seconds allowed for the TCP/TLS connect and the handshake response together, as one deadline (client only). |
sslContext | array<string,mixed> | TLS options for wss:// (client only), in the shape of a stream context's ssl options: verify_peer, cafile, and so on. |
protocols | array<int,string> | Subprotocols, in order of preference. |
allowedOrigins | array<int,string> | Origins allowed to upgrade (server only). |
compression | bool | Negotiate permessage-deflate (RFC 7692) compression. |
compressionMinBytes | int | With compression on, only messages of at least this many bytes are compressed. |
maxMessageSize#source
int $maxMessageSize = 16777216
Largest accepted message, in bytes, after reassembly and decompression. Default 16 MiB. A bigger message closes the connection with 1009.
maxFrameSize#source
int $maxFrameSize = 16777216
Largest accepted single frame payload, in bytes. Default 16 MiB. Checked from the frame header before the payload is read; a bigger frame closes the connection with 1009.
pingInterval#source
float $pingInterval = 30.0
Seconds of silence before a ping is sent; also the read timeout. Default 30. 0 turns keepalive off.
pongTimeout#source
float $pongTimeout = 10.0
Seconds to wait for the answer to a keepalive ping before the connection is dropped (close code 1006). Default 10.
closeTimeout#source
float $closeTimeout = 5.0
Seconds to wait for the peer's Close frame after sending ours. Default 5.
connectTimeout#source
float $connectTimeout = 10.0
Seconds allowed for the TCP/TLS connect and the handshake response together, as one deadline (client only). Default 10.
sslContext#source
array<string,mixed> $sslContext = []
TLS options for wss:// (client only), in the shape of a stream context's ssl options: verify_peer, cafile, and so on. Default empty. SNI and the peer name are filled in from the URL's host.
protocols#source
array<int,string> $protocols = []
Subprotocols, in order of preference. Default empty.
Server: the first entry of the client's Sec-WebSocket-Protocol list that
is also in this array is chosen; with no match no protocol header is sent.
Client: all entries are offered, and a protocol the server answers with
must be one of them.
allowedOrigins#source
array<int,string> $allowedOrigins = []
Origins allowed to upgrade (server only). Default empty, which checks nothing. When non-empty, a request whose Origin header is not an exact member of this list (including a request with no Origin) gets a 403. Set it whenever the connection is privileged: a browser sends cookies on a cross-site WebSocket upgrade and CORS does not police it.
compression#source
bool $compression = false
Negotiate permessage-deflate (RFC 7692) compression. Default off; turn it on at both ends.
compressionMinBytes#source
int $compressionMinBytes = 256
With compression on, only messages of at least this many bytes are compressed. Default 256.
Methods
maxMessageSize() | Set {@see $maxMessageSize}. |
maxFrameSize() | Set {@see $maxFrameSize}. |
pingInterval() | Set {@see $pingInterval}. |
pongTimeout() | Set {@see $pongTimeout}. |
closeTimeout() | Set {@see $closeTimeout}. |
connectTimeout() | Set {@see $connectTimeout}. |
sslContext() | Set {@see $sslContext}. |
protocols() | Set {@see $protocols}. |
allowedOrigins() | Set {@see $allowedOrigins}. |
compression() | Set {@see $compression}. |
compressionMinBytes() | Set {@see $compressionMinBytes}. |
maxMessageSize()#source
function maxMessageSize(int $n): Options
Set {@see $maxMessageSize}. Also lowers {@see $maxFrameSize} when that is larger than the new limit.
Parameters
$nint- limit in bytes
Returns
Options — this object
maxFrameSize()#source
function maxFrameSize(int $n): Options
Set {@see $maxFrameSize}.
Parameters
$nint- limit in bytes
Returns
Options — this object
pingInterval()#source
function pingInterval(float $s): Options
Set {@see $pingInterval}.
Parameters
$sfloat- seconds; 0 turns keepalive off
Returns
Options — this object
pongTimeout()#source
function pongTimeout(float $s): Options
Set {@see $pongTimeout}.
Parameters
$sfloat- seconds
Returns
Options — this object
closeTimeout()#source
function closeTimeout(float $s): Options
Set {@see $closeTimeout}.
Parameters
$sfloat- seconds
Returns
Options — this object
connectTimeout()#source
function connectTimeout(float $s): Options
Set {@see $connectTimeout}.
Parameters
$sfloat- seconds
Returns
Options — this object
sslContext()#source
function sslContext(array<string,mixed> $ssl): Options
Set {@see $sslContext}.
Parameters
$sslarray<string,mixed>sslstream-context options
Returns
Options — this object
protocols()#source
function protocols(array<int,string> $p): Options
Set {@see $protocols}.
Parameters
$parray<int,string>- subprotocol names, most preferred first
Returns
Options — this object
allowedOrigins()#source
function allowedOrigins(array<int,string> $o): Options
Set {@see $allowedOrigins}.
Parameters
$oarray<int,string>- allowed
Originvalues, for examplehttps://example.com
Returns
Options — this object
compression()#source
function compression(bool $on): Options
Set {@see $compression}.
Parameters
$onbool- true to negotiate permessage-deflate
Returns
Options — this object
compressionMinBytes()#source
function compressionMinBytes(int $n): Options
Set {@see $compressionMinBytes}.
Parameters
$nint- threshold in bytes
Returns
Options — this object