WebSockets
About 1 min
WebSockets
Low-level WebSocket handshake and framing helpers.
class WebSocketsProperties
allowedProtocols
protected array $allowedProtocolsType: array
magicGUID
RFC6455 GUID used for Sec-WebSocket-Accept validation.
private string $magicGUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'Type: string
headers
private array $headersType: array
Methods
__construct
public __construct(array $allowedProtocols): voidParameters
| Parameter | Type | Description |
|---|---|---|
$allowedProtocols | array |
parseHeaders
public parseHeaders(string $request, string $body): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$request | string | |
$body | string |
createHandshake
protected createHandshake(string $path, string $host, ?string $origin, string $key, ?array $extraHeaders): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | |
$host | string | |
$origin | string | |
$key | string | |
$extraHeaders | array |
acceptHandshake
protected acceptHandshake(array|string $headers, array $responseHeaders, ?string $key, array $results): bool|intReturns: bool|int
Parameters
| Parameter | Type | Description |
|---|---|---|
$headers | array | string |
$responseHeaders | array | |
$key | string | |
$results | array |
frame
Encodes a payload into a WebSocket frame.
protected frame(string $payload, ?string $type, bool $masked = true): false|stringReturns: false|string
Parameters
| Parameter | Type | Description |
|---|---|---|
$payload | string | |
$type | string | |
$masked | bool |
getFrame
Extracts one frame from the provided receive buffer.
protected getFrame(string $buffer, ?string $payload): bool|intReturns: bool|int
Parameters
| Parameter | Type | Description |
|---|---|---|
$buffer | string | |
$payload | string |
checkHost
Validates the Host header in a handshake request.
protected checkHost(string $host): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$host | string |
checkRequestURL
protected checkRequestURL(string $path): array|boolReturns: array|bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string |
checkOrigin
Validates the Origin header in a handshake request.
protected checkOrigin(string $origin): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$origin | string |
checkProtocol
protected checkProtocol(array|string $protocols): array|falseReturns: array|false
Parameters
| Parameter | Type | Description |
|---|---|---|
$protocols | array | string |
hexString
protected hexString(string $string): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$string | string |
getFrameHeaders
private getFrameHeaders(string $frame): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$frame | string |
applyMask
private applyMask(array $headers, string $payload): ?stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$headers | array | |
$payload | string |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:17 +0000