Search code examples
phplaravelreactphp

How to connect wss via ReactPHP components


I have a URI that works well with a js implementation, built as: "wss://domain"

When I want to implement a subscriber for this socket as below:

        $loop = Factory::create();

        $connector = new Connector($loop);

        $promise = $connector->connect($uri);

        $promise->then(function(ConnectionInterface $connection) {
            $connection->on('data', function ($data) {
                echo $data;
            });
        }, function (\Exception $e) {
            echo $e->getMessage();
        });

        $loop->run();

The promise catches the exception with the message: "No connector available for URI scheme "wss"% "

I can't find any connector for wss. Is there any connectors that I can use directly? Or should I wrap with another connector?


Solution

  • Hey ReactPHP core maintainer here, react/socket only supports low level connections like UDP, TCP etc where you have to implement the protocols on that connection. react/http does that for HTTP, and https://github.com/ratchetphp/Pawl is a WebSocket client for ReactPHP, which builds on top of those two mentioned earlier