PHP Websocket Client

1.8k Views Asked by At

I'm currently attempting to create a WebSocket client to connect to a wss:// URL with PHP (without using JavaScript). It's been a few days trying to program a simple function or class that can do so.

I tried and looked into fsockopen, various streams, and also Racket but failed to see in their docs a client class. Is this possible with PHP? Code sample or any direction would be appreciated.

1

There are 1 best solutions below

0
Oliver M Grech On BEST ANSWER

For anyone looking in the future this is what I found and used. Walk in the park.

PHP-WSS

<?php
use WSSC\WebSocketClient;
use \WSSC\Components\ClientConfig;

$client = new WebSocketClient('ws://localhost:8000/notifications/messanger/yourtoken123', new ClientConfig());
$client->send('{"user_id" : 123}');
echo $client->receive();