只使用redis socketio来与Php进行通信,反之亦然

只使用redis socketio来与Php进行通信,反之亦然

对于laravel中的这类事件来说,我相当陌生,但是我不太清楚如何使用Laravel在socketio和php之间进行通信。

我相当新的这个框架,请容易在我身上。

我已经知道如何从PHP到Nodejs socketio进行通信,但问题是我不知道相反的通信是如何工作的! 一世

注意:我的PHP会话是REDIS

这是我的命令

class ChatCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'command:name'; /** * The console command description. * * @var string */ protected $description = 'Command description'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { // Redis::psubscribe(['*'], function($message) { DebugBar::info(message); event(new TestEvent()); Log::info($message); }); } } 

我的socket.js

 var io = require('socket.io')(http); var Redis = require('ioredis'); var redis = new Redis(); var redis1 = new Redis(); //omitted some code here http.listen(3000, function(){ console.log('Listening on Port 3000'); }); io.on('connection', function(socket){ socket.on('chat', function(msg){ io.emit('chat', msg); console.log(msg); redis1.publish('chat' , msg); }); }); 

我可以在redis-cli看到:

使用命令subscribe *

 1) "message" 2) "chat" 3) "[object Object]" 

这意味着redis1.publish工程,但我不知道为什么我不能订阅我的Php Laravel应用程序“?