-1

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.

Karl Hill
  • 12,937
  • 5
  • 58
  • 95
Oliver M Grech
  • 3,071
  • 1
  • 21
  • 36
  • 1
    It is 100% possible with PHP. Show us your code and problem so it can be solved. – Saud Jul 03 '21 at 09:16
  • 1
    It's certainly possible. Don't re-invent the wheel though - [start here](https://www.google.com/search?q=php+websocket+client) – ADyson Jul 03 '21 at 09:43
  • Thank you guys your comments gave me courage to look further. Found the solution. Any other tips and tricks more than welcome maybe it helps others – Oliver M Grech Jul 03 '21 at 09:46

1 Answers1

2

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();
Oliver M Grech
  • 3,071
  • 1
  • 21
  • 36