【发布时间】: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?我错过了什么?
【问题讨论】: