ratchet/pawl
Async WebSocket client for PHP built on ReactPHP promises. Connect to ws/wss endpoints, negotiate subprotocols, send custom headers, and handle messages via event-driven callbacks. Includes Connector/WebSocket/Message APIs and Autobahn-tested compatibility.
Begin by installing the package: composer require ratchet/pawl. The primary entry points are the Connector class (for full control) and the convenience static connect() helper (a wrapper around Connector). Start with the minimal use case from the README: connect to a public echo server, send a message, receive it back, and exit. This validates your environment and confirms async event loop functionality. Next, read the Classes section to understand Connector, WebSocket, and MessageInterface. Ensure you’re using PHP 7.4+, and verify ReactPHP’s event loop integration—Pawl uses the default loop unless you inject a custom one.
Loop::run() to keep the process alive and attach message/close handlers for stateful interaction.React\Socket\Connector into Connector to configure DNS, timeouts, and TLS—enabling robust, production-grade client behavior.graphql-ws or vnd.api+json during handshake to consume structured WebSocket APIs (e.g., Apollo subscriptions).Connector instance to manage many concurrent connections—e.g., fan-out notifications across multiple external services—without blocking PHP’s main thread.Authorization: Bearer ...) during connection to authenticate with secured WebSocket endpoints.wss:// connections, configure TLS options (e.g., verify_peer) via the injected React\Socket\Connector. Never disable verification in production.$conn->close()) or attach cleanup logic to promise cancellation (then(null, null, fn() => $conn->close())). Unbalanced connections leak file descriptors.__toString() returns UTF-8 text only. Use $msg->getPayload() for binary data, and pair with unpack() or stream_get_contents() for structured decoding.connect_timeout in the React connector if dealing with high-latency endpoints.Exception—always include a second callback in then() to handle connection failures, and ensure $loop->stop() is called on fatal errors in CLI scripts.How can I help you explore Laravel packages today?