Laravel5.2 broadcaster cannot broadcast without error?

  node.js, question

Environment: Mac, laravel Version 5.2.x, valet

Problem description:

Error occurred when using laravel to cooperate with nodeJS socket.io to make websocket.

This is the socket server code

var http = require('http').Server();
 var io = require('socket.io')(http);
 var Redis = require('ioredis');
 var redis = new Redis();
 
 redis.subscribe('test-channel');
 
 redis.on('message', function (channel, message) {
 console.log(message);
 message = JSON.parse(message);
 Io.emit(channel plus':' plus message.event, message.data);
 });
 
 http.listen(3001, function () {
 console.log('Server is running at 3001!'  );
 });

This is the route code.

Route::get('/test', function () {
 
 $data = [
 'event' => 'inbox',
 'data' => [
 'name' => 'WTF'
 bracket
 ];
 
 Redis::publish('test-channel', json_encode($data));
 
 return 'Done';
 });

After accessing the /test page, the command line displays as follows:

图片描述

The front-end has also received the data and will not show it. The crux of the problem lies in

When I changed the code of route to read as follows:

Route::get('/test', function () {
 
 event(new \App\Events\Test('ARE U OK ?'  ));
 
 return 'Done';
 });

Then through

php artisan make:event Test

The generated event event code is as follows:

<?  php
 
 namespace App\Events;
 
 use App\Events\Event;
 use Illuminate\Queue\SerializesModels;
 use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
 
 class Test extends Event implements ShouldBroadcast
 bracket
 use SerializesModels;
 
 public $name;
 
 public function __construct($name)
 bracket
 $this->name = $name;
 bracket
 
 public function broadcastOn()
 bracket
 return ['test-channel'];
 bracket
 bracket

Then visit the /test page,Command line no output.

Before that, it was configured with broadcast’s driver.

Env document inside

BROADCAST_DRIVER=redis

Config’s cache has also been clear.

From the success of using Redis::publish, we can see that laravel and Redis links are successful, so what should be the problem?

Please advise the great god!

After restarting the project, copying the same code and executing normally, it was found that the problem caused by QUEUE_DRIVER=redis of the original project should be the problem of queue.

Change QUEUE_DRIVER=redis to sync.