Laravel Redis活动广播

时间:2016-02-29 19:25:22

标签: laravel redis

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

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使用pusher即使我配置它使用redis?我错过了什么?

1 个答案:

答案 0 :(得分:4)

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

php artisan config:clear