Cannot get server get the socket
I know php emmiter is emiting the sockets, but server is not getting them.
This is my php code
$redis = new \Redis();
$redis->connect('127.0.0.1', '6379');
$emitter = new SocketIO\Emitter($redis);
$emitter->broadcast->emit('haha', 'such data');
This is my server code
var io = require('socket.io')(3000);
var redis = require('socket.io-redis');
io.adapter(redis({ host: '127.0.0.1', port: 6379 }));
io.on('connection', function(socket){
console.log(socket + " connected");
socket.on('haha', function(data){
console.log("data " + data);
});
socket.on('disconnect', function(){
console.log(socket + " disconnected");
});
});
redis-cli monitor output:
1466856693.275138 [0 127.0.0.1:34296] "info"
1466856693.276242 [0 127.0.0.1:34298] "info"
1466856693.284131 [0 127.0.0.1:34298] "subscribe" "socket.io#/#" //nodejs server start
1466856702.934495 [0 127.0.0.1:34332] "PUBLISH" "socket.io#/#" "\x93\xa7emitter\x83\xa4type\x02\xa4data\x92\xa4haha\xa9such data\xa3nsp\xa1/\x82\xa5rooms\x90\xa5flags\x81\xa9broadcast\xc3" //php code exec
Im running Ubuntu Server 16.04 with php7, node 4.4.6, redis-server 3.0.6. Any ideas why it doesnt work? Thanks a lot!
This is related to broken compatibility between socket.io-redis and socket.io-php-emitter, and there is PR for that, for few months already: https://github.com/rase-/socket.io-php-emitter/pull/21 but @rase- seems to not bothering about state of his repo. Instead I'd suggest you to use @ashiina package: https://packagist.org/packages/ashiina/socket.io-emitter which is basically his PR merged.
@aPoCoMiLogin Im using his package and it is not working, should i use older version of socket.io-redis? What version should i use? Thanks composer info:
ashiina/socket.io-emitter 0.8.0 *Maintained* A PHP implementation of socket...
ptrofimov/tinyredisclient 1.1.1 The most lightweight Redis client written i...