Open ClosetGeek-Git opened 1 year ago
You can use \React\Socket\FixedUriConnector to use UDS in pawl:
$loop = \React\EventLoop\Loop::get();
$connector = new \Ratchet\Client\Connector(
$loop,
new \React\Socket\FixedUriConnector('unix:///tmp/my-ws.sock', new \React\Socket\UnixConnector($loop))
);
$connector('ws://127.0.0.1/my-path')
->then(function (\Ratchet\Client\WebSocket $conn) {
// connection established
});
It's common for Websocket services to operate behind a reverse proxy, such as can be provided by Nginx or Apache. A common use case is to create this proxy connection over Unix Domain sockets rather than TCP because 1) UDS typically has somewhat better throughput and lower latency, sometimes significantly better. 2) Each time a new client connects the the forward facing service (Nginx/Apache), the proxy must create a new connection from itself into the Websocket service, effectively doubling the amount of TCP connections on the OS
This is possible in other high-level websocket frameworks such as socket.io and Django, and is also possible in Ratchet and should likely have first class support. For example:
Apache conf (ratchet_proxy.sock wouldn't live in /var/www if the code above is started as a deamon): In this example any requests / ws connections on http://<domain>/api will be proxied into ratchet while all others are handled by using mod_php or PHP-FPM depending on configuration.
Additionally this is also possible in ratchetphp/Pawl, however the Ratchet\Client\Connector forces a ws/wss uri. UDS works in pawl with a hackish work around (this is just for example purpose).
ws_client.php
hack: in ratchet/pawl/src/Connector.php replace lines 38 - 53 the following (note the spoofed uri in generateRequest() ):