I had a need to connect to websocket via php, send data and immediately disconnect. No need to wait for a response from the socket. I used elefant.io but after updating the library does not work. Please tell me how to connect to websocket via PHP?
Asked
Active
Viewed 8,370 times
2 Answers
8
I also encountered this problem. Learned a lot of structure websocket requests. I wrote a library for yourself, you can use it.PHP SocketIO Client.
You need simple socket connect to nodejs, compose in this message format.42["message", "your message"]
' To encode to hybi10 (or hybi13) and send to websocket

SlyBeaver
- 1,272
- 12
- 22
-
Also, you can download any websoket library, but edit and put something like $header .= "GET /socket.io/?EIO=2&transport=websocket HTTP/1.1\r\n"; to socket.io server library work. Spent 2 hours trying to understand – Velaro Jan 15 '19 at 14:11
-3
var socket = require( 'socket.io' );
var express = require( 'express' );
var http = require( 'http' );
var app = express();
var server = http.createServer( app );
var io = socket.listen( server );
io.sockets.on( 'connection', function( client ) {
console.log( "New client !" );

Cyrus Mohammadian
- 4,982
- 6
- 33
- 62

deibu
- 1
- 3
-
Please format your post and add some explanation to what the code does – Anton Sarov Mar 14 '16 at 07:35