0

I've been trying to implement a PHP client for socket.io v4. Though this looks easy, I've noticed the following trends within GitHub:

  1. The client is a Redis emitter (?)
  2. The client is not compatible with socket.io v4
  3. The client simply is not connecting to the socket.io server (encryption issue I guess)

The question remains, however. Is there a compatible PHP client class for socket.io v4?


This client is the one that looks ok but is not compatible with v4.

First, on line 77 I've updated the code to make the queries compatible with socket.io v4:

public function __construct($host = null, $port = null, $path = "/socket.io/?EIO=4")

Diving a little deeper on line 311, php is writing the encrypted data onto the socket. This is where the handshake is performed. But no correct data is being sent over the socket.

fwrite($fd, $this->hybi10Encode('42["' . $this->event . '", "' . addslashes($this->getData()) . '"]'));
  • Questions seeking recommendations for libraries are off-topic. Please see [**What topics can I ask about here?**](https://stackoverflow.com/help/on-topic) – Alex Howansky Apr 20 '22 at 15:32
  • you can checkout this one https://github.com/ratchetphp/Ratchet – Rudra Apr 20 '22 at 16:29
  • Thanks @Rudra, but again Ratchet is a server-side implementation. – Cena Ebrahimiyan Apr 20 '22 at 16:47
  • @AlexHowansky, although the question is seeking a library, it is also asking for a workaround to make the hybi10Encode function compatible with the socketio v4. – Cena Ebrahimiyan Apr 20 '22 at 16:49
  • _"Ratchet is a server-side implementation"_ You asked for a PHP solution. PHP is server side. It's a "client" in the sense that it consumes an API from a remote server, but the PHP code still runs server side. – Alex Howansky Apr 20 '22 at 17:03
  • _"it is also asking for a workaround to make the hybi10Encode function compatible"_ There is no such detail in your question. If this is the actual issue you're experiencing, please update the question with the appropriate information. – Alex Howansky Apr 20 '22 at 17:06
  • @AlexHowansky _"You asked for a PHP solution"_ please note that socket.io client could be called from a server-side runtime (in this case php). To elaborate, socket client has nothing to do with the side the php is on as long as it is calling (emitting) events on the socket. – Cena Ebrahimiyan Apr 21 '22 at 00:24
  • @CenaEbrahimiyan Did you get any good libraries to work with Socket.IO v4? – Tom Jun 30 '22 at 19:42
  • 1
    Hello @Tom, as of now, I'm using the "allowEIO3" flag on the server script alongside with the client mentioned in the question. Works fine, but apparently the encoding is a bit different on socket.io v4. – Cena Ebrahimiyan Jul 06 '22 at 19:04
  • @CenaEbrahimiyan Are you using SocketIO v4 or have you stayed on SocketIO v3? – Tom Jul 06 '22 at 23:05
  • 1
    @Tom I'm on Socket.io v4. – Cena Ebrahimiyan Aug 06 '22 at 13:46
  • @CenaEbrahimiyan even I set "allowEIO3" flag, [this client script](https://github.com/touskar/php-socket-io-event-emitter) can not connect or can not send commands to the socket server, which client PHP script are you using now? – woheras Aug 29 '22 at 15:56
  • I'm using the one same as yours without any problems. I think it's a mistake on your part. I'd be happy to look over your code. @woheras – Cena Ebrahimiyan Aug 31 '22 at 19:16

0 Answers0