Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Rfc6455 Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Middleware-based Integration (Laravel): In a Laravel app, implement a custom 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 Encoding/Decoding: Use 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.
  • Compression Support: Enable permessage-deflate by setting Extension::HEADER_PERMESSAGE_DEFLATE in the handshake offer (handled in ServerHandshake::createResponse()), and configure Frame::$enableCompression.
  • Subprotocol Selection: Use ServerHandshake::createResponse() with the list of supported subprotocols — the library will parse Sec-WebSocket-Protocol headers and match correctly, even across comma-separated values.

Gotchas and Tips

  • No I/O: This package does not handle sockets or streams. You must integrate with ReactPHP, Amp, or Symfony’s HttpKernel (via StreamedResponse) to transmit data.
  • Memory Usage: Frame buffering can accumulate data on slow clients — always configure MessageBuffer::$maxBufferLength (default 2 MB) and handle MessageBuffer::EVENT_CLOSE with appropriate close codes (1009 for message too big).
  • PHP 32-bit Limits: Though v0.4+ supports payloads up to 2GB, remember PHP’s memory limits and integer size constraints — avoid processing very large binary frames on 32-bit systems.
  • PSR-7 Abstraction: You’ll need PSR-17 factories for request/response construction (e.g., nyholm/psr7). The library expects PSR-7 objects for handshake negotiation, but not for ongoing communication.
  • UTF-8 Validation: The library strictly validates UTF-8 payload in text frames — enable Frame::$strictUTF8Validation (default true) only in production if strict compliance is needed; otherwise disable it for throughput.
  • Debugging: Wrap frame processing in try/catch — malformed frames throw ProtocolException with descriptive messages. Enable logging for Frame and MessageBuffer events during development.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport