phasync\Util\Protocols\WebSocketFrame class

Documentation

This class provides a implementation for parsing and creating WebSocket frames according to the WebSocket protocol specification (RFC 6455).

To parse a WebSocket frame from a StringBuffer:

$frame = WebSocketFrame::parse($stringBuffer);
if ($frame !== null) {
  $payload = $frame->getPayload(); // Gets the frame payload
  $opcode = $frame->getOpcode(); // Gets the frame opcode
}

To create a WebSocket frame:

$frame = WebSocketFrame::popInstance() ?? new WebSocketFrame();
$frame->setPayload("Hello, WebSocket!");
$frame->setFin(true);
$frame->setOpcode(WebSocketFrame::TEXT_FRAME);
$frameData = $frame->toString(); // Binary WebSocket frame as a string

Inheritance

Implements: phasync\Internal\ObjectPoolInterface

Uses Traits: phasync\Internal\ObjectPoolTrait

Constants (6)

NameValue
CONTINUATION_FRAME 0
TEXT_FRAME 1
BINARY_FRAME 2
CONNECTION_CLOSE 8
PING 9
PONG 10

Properties (4)

public int $opcode
public string $payload
private static array $pool
private static int $instanceCount

Methods (16)

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Source

src/Util/Protocols/WebSocketFrame.php:33-200