【问题标题】:Laravel Redis event broadcastingLaravel Redis 事件广播
【发布时间】:2016-06-12 23:37:06
【问题描述】:

我正在尝试使用 redis 作为 laravel 中的默认广播器,这是我的 .env 填充

QUEUE_DRIVER=sync
APP_ENV=local
APP_DEBUG=true
APP_KEY=***********
DB_HOST=***************
DB_PORT=******************
DB_DATABASE=***************

DB_USERNAME=***********
DB_PASSWORD=*************

CACHE_DRIVER=file
SESSION_DRIVER=file

BROADCAST_DRIVER=redis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

我正在使用这个事件类来广播

 <?php

namespace App\Events;

use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Queue\SerializesModels;
use Log ;
class SomeEvent extends Event implements ShouldBroadcast
{
    use SerializesModels;

    public $data;

    public function __construct($room, $data)
    {
        Log::debug($room);
        Log::debug($data);

        $this->data = array(
            'room' => $room,
            'data' => $data
        );
    }

    public function broadcastOn()
    {
        Log::debug('in channel!!!');

        return ['test-channel'];
    }
}

当我使用

在控制器内触发事件时
 event(new SomeEvent("test room", "test message"));

我收到以下错误

[2016-02-29 19:17:38] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'Pusher' not found' in C:\xampp\htdocs\TechInsights\vendor\laravel\framework\src\Illuminate\Broadcasting\BroadcastManager.php:132
Stack trace:

最奇怪的是当我更改 BroadcastManager.php 中的 createPusherDriver 方法时

来自

 protected function createPusherDriver(array $config)
    {
        return new PusherBroadcaster(
            new Pusher($config['key'], $config['secret'], $config['app_id'], Arr::get($config, 'options', []))
        );
    }

  protected function createPusherDriver(array $config)
    {
        return new RedisBroadcaster(
            $this->app->make('redis'), Arr::get($config, 'connection')
        );
    }

事件在 redis 中广播没有任何问题!有任何想法吗 ?即使我将 laravel 配置为使用 redis,为什么还要使用 pusher?我错过了什么?

【问题讨论】:

    标签: laravel redis


    【解决方案1】:

    您是否尝试过清除配置缓存?

    php artisan config:clear
    

    【讨论】:

      猜你喜欢
      • 2021-08-15
      • 2015-09-10
      • 2015-08-29
      • 2017-04-28
      • 2017-05-04
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 2020-07-28
      相关资源
      最近更新 更多