事件不会在laravel中的redis中发布

时间:2017-07-09 19:18:41

标签: php laravel websocket redis laravel-echo

我想用laravel echo和redis开发实时应用程序 但它不起作用 即:当我开火事件时没有发生任何事情 我检查redis是好的,但我不知道如何纠正这个问题

事件:

   class testevent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $data;
/**
 * Create a new event instance.
 *
 * @return void
 */
public function __construct()
{
    //
  $this->data="sdf";

}

/**
 * Get the channels the event should broadcast on.
 *
 * @return Channel|array
 */
public function broadcastOn()
{

    return ['testCh'];
}
}

火:

  Route::get('test',function ()
 {
event(new testevent());

return 1;

 });


⚠ Starting server in DEV mode...

✔  Running at localhost on port 6001
✔  Channels are ready.
✔  Listening for http events...
✔  Listening for redis events...

Server ready!

js file:

 import Echo from "laravel-echo"
 window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001'
    });
console.log("sdfsdffdnpm")
window.Echo.channel('testCh')
.listen('.testevent', () => {
    console.log("sooooooooooooooooo");
});

1 个答案:

答案 0 :(得分:1)

  

config / app.php确保你有

    gcc -pthread -o p3 p3.c -lm
  你的.env

中的

     App\Providers\BroadcastServiceProvider::class,

运行 BROADCAST_DRIVER=redis

我希望这会有所帮助