ratchet/rfc6455
Protocol handler for RFC6455 WebSockets. Provides server/client handshake and message framing/negotiation components while staying framework-agnostic and I/O-free. Leaves spec ambiguities to implementers and integrates HTTP upgrade via PSR-7 interfaces.
Start by installing the package via Composer: composer require ratchet/rfc6455. This is a low-level, I/O-agnostic WebSocket protocol implementation — it handles framing, handshake negotiation, and message assembly without networking or event loop concerns. Your first real use case will be implementing a WebSocket server or client on top of this layer, typically using a library like react/socket, amphp/http, or within a Laravel app via custom middleware (e.g., integrating with PSR-7/15 requests/responses). To begin, examine the ClientHandshake, ServerHandshake, Frame, and MessageBuffer classes in src/ — they form the core building blocks for decoding/encoding frames and performing RFC6455-compliant handshakes.
Middleware that intercepts GET /ws requests, delegates the handshake to ServerHandshake, and upgrades the PSR-7 response. After handshake succeeds, replace the response with your custom streaming response (e.g., Amp\Http\Server\Response) or buffer frames manually.Frame::fromBuffer() and Frame::create() for parsing incoming raw bytes or serializing outgoing frames. Always wrap frames in MessageBuffer to reconstruct complete messages from fragmented frames.Extension::HEADER_PERMESSAGE_DEFLATE in the handshake offer (handled in ServerHandshake::createResponse()), and configure Frame::$enableCompression.ServerHandshake::createResponse() with the list of supported subprotocols — the library will parse Sec-WebSocket-Protocol headers and match correctly, even across comma-separated values.StreamedResponse) to transmit data.MessageBuffer::$maxBufferLength (default 2 MB) and handle MessageBuffer::EVENT_CLOSE with appropriate close codes (1009 for message too big).nyholm/psr7). The library expects PSR-7 objects for handshake negotiation, but not for ongoing communication.Frame::$strictUTF8Validation (default true) only in production if strict compliance is needed; otherwise disable it for throughput.try/catch — malformed frames throw ProtocolException with descriptive messages. Enable logging for Frame and MessageBuffer events during development.How can I help you explore Laravel packages today?