2

I am using socketio to run a websocket server.

var fs = require('fs');
var options = {
  key: fs.readFileSync('/etc/letsencrypt/live/my.domain.be/privkey.pem'),
  cert: fs.readFileSync('/etc/letsencrypt/live/my.domain.be/fullchain.pem')
};
var app = require('https').createServer(options)
  , io = require('socket.io').listen(app)

app.listen(6666);

Connecting to it from javascript (using socket.io client) works fine.

var socket = io.connect('wss://my.domain.be:6666');

This works also :

var socket = io.connect('https://my.domain.be:6666');

Now I want to connect using php. I found a simple php client here : How can I send data/text from PHP using WebSocket to process?

But I see no incoming connection when using :

$WebSocketClient = new WebsocketClient('wss://my.domain.be', 6666);
$WebSocketClient->sendData("MyUserNameFromPHP");

And I get the error :

Error: 22145040:Unable to find the socket transport "wss" - did you forget to enable it when you configured PHP?

When using :

$WebSocketClient = new WebsocketClient('https://my.domain.be', 6666);

I get the error :

Error: 10905616:Unable to find the socket transport "https" - did you forget to enable it when you configured PHP?

When using tls:// or ssl:// I get no output at all (and still no connection on my websocket server).

So what am I missing to make a websocket connection from my php code ?

user2795648
  • 119
  • 1
  • 11
  • Have you tried `$WebSocketClient = new WebsocketClient('https://my.domain.be', 6666);` ? It would seem that "wss" is a socket transport protocol that must be manually added to php (not 100% on this, just what I gather from that error message). – whitwhoa Nov 21 '17 at 14:47
  • Then I get : Unable to find the socket transport "https" (added to my original post) – user2795648 Nov 21 '17 at 15:08
  • Try using the ip address of the websocket server instead of the domain name (no protocol or anything in front of it) For example: `$WebSocketClient = new WebsocketClient('111.111.111.111', 6666);` – whitwhoa Nov 21 '17 at 15:19
  • Connection on ip address will be refused because the ssl certificate is only valid for the domain "my.domain.be". Although that is what my web-browser tells me when I try this in javascript code (socket.io). Testing this in php gives again no output at all (and no connection on my websocket server). – user2795648 Nov 21 '17 at 15:49
  • Could this be of any help? https://stackoverflow.com/a/28393526/1025702 Maybe you need to enable wss in apache or whatever server you're using? – Matt Fletcher Nov 23 '17 at 14:16
  • Hello Matt. If I understand correctly I need httpd24 & php56 to be able to use websockets from within php. Upgrading from httpd v2.2 to v2.4 is not such a small intervention. But if this is the only way... – user2795648 Nov 29 '17 at 09:07

1 Answers1

0

https://stackoverflow.com/a/61808878/3701985 please try my answer on another similar thread, I actually tried multiple solutions and now just want to provide answer which worked for me. https://github.com/ratchetphp/Pawl

Mayank Tiwari
  • 919
  • 1
  • 6
  • 13