Laravel Lumen + Broadcasting + Redis + Class pusher not found
Posted
技术标签:
【中文标题】Laravel Lumen + Broadcasting + Redis + Class pusher not found【英文标题】: 【发布时间】:2018-09-26 03:09:35 【问题描述】:所以我正在尝试使用 redis 设置广播,但是我无法让它工作,因为我想我缺少一些配置选项。
.env 文件
...
BROADCAST_DRIVER=redis
...
控制器
event(new TestEvent());
TestEvent.php
<?php
namespace App\Events\Socket;
use App\Events\Event;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class TestEvent implements ShouldBroadcast
protected $data;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct()
$this->data = [
'payload' => [
'test' => 'test'
],
'message' => 'another'
];
public function broadcastOn()
return new PrivateChannel('user.2');
但是,当我在数据库的 failed_jobs 表中运行它时,会弹出此错误:
Symfony\Component\Debug\Exception\FatalThrowableError: 在 /var/www/vendor/illuminate/broadcasting/BroadcastManager.php:216 中找不到类“Pusher” 堆栈跟踪:
0 /var/www/vendor/illuminate/broadcasting/BroadcastManager.php(193): Illuminate\Broadcasting\BroadcastManager->createPusherDriver(Array)
1 /var/www/vendor/illuminate/broadcasting/BroadcastManager.php(164): Illuminate\Broadcasting\BroadcastManager->resolve('pusher')
2 /var/www/vendor/illuminate/broadcasting/BroadcastManager.php(153): Illuminate\Broadcasting\BroadcastManager->get('pusher')
3 /var/www/vendor/illuminate/broadcasting/BroadcastManager.php(140): Illuminate\Broadcasting\BroadcastManager->driver('pusher')
4 /var/www/vendor/illuminate/broadcasting/BroadcastServiceProvider.php(30): Illuminate\Broadcasting\BroadcastManager->connection()
5 /var/www/vendor/illuminate/container/Container.php(726): Illuminate\Broadcasting\BroadcastServiceProvider->Illuminate\Broadcastingclosure(Object(Laravel\Lumen\Application), Array)
6 /var/www/vendor/illuminate/container/Container.php(608): Illuminate\Container\Container->build(Object(Closure))
7 /var/www/vendor/illuminate/container/Container.php(575): Illuminate\Container\Container->resolve('Illuminate\Cont...')
8 /var/www/vendor/laravel/lumen-framework/src/Application.php(210): Illuminate\Container\Container->make('Illuminate\Cont...')
9 /var/www/vendor/illuminate/container/BoundMethod.php(156): Laravel\Lumen\Application->make('Illuminate\Cont...')
10 /var/www/vendor/illuminate/container/BoundMethod.php(116): Illuminate\Container\BoundMethod::addDependencyForCallParameter(Object(Laravel\Lumen\Application), Object(ReflectionParameter), Array, Array)
11 /var/www/vendor/illuminate/container/BoundMethod.php(29): Illuminate\Container\BoundMethod::getMethodDependencies(Object(Laravel\Lumen\Application), Array, Array)
12 /var/www/vendor/illuminate/container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Containerclosure()
13 /var/www/vendor/illuminate/container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
14 /var/www/vendor/illuminate/container/Container.php(539): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
15 /var/www/vendor/illuminate/bus/Dispatcher.php(94): Illuminate\Container\Container->call(Array)
16 /var/www/vendor/illuminate/pipeline/Pipeline.php(114): Illuminate\Bus\Dispatcher->Illuminate\Busclosure(Object(Illuminate\Broadcasting\BroadcastEvent))
17 /var/www/vendor/illuminate/pipeline/Pipeline.php(102): Illuminate\Pipeline\Pipeline->Illuminate\Pipelineclosure(Object(Illuminate\Broadcasting\BroadcastEvent))
18 /var/www/vendor/illuminate/bus/Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
19 /var/www/vendor/illuminate/queue/CallQueuedHandler.php(42): Illuminate\Bus\Dispatcher->dispatchNow(Object(Illuminate\Broadcasting\BroadcastEvent), false)
20 /var/www/vendor/illuminate/queue/Jobs/Job.php(69): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
21 /var/www/vendor/illuminate/queue/Worker.php(317): Illuminate\Queue\Jobs\Job->fire()
22 /var/www/vendor/illuminate/queue/Worker.php(267): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\队列\WorkerOptions))
23 /var/www/vendor/illuminate/queue/Worker.php(113): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\队列\WorkerOptions))
24 /var/www/vendor/illuminate/queue/Console/WorkCommand.php(101): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
25 /var/www/vendor/illuminate/queue/Console/WorkCommand.php(85): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
26【内部函数】:Illuminate\Queue\Console\WorkCommand->fire()
27 /var/www/vendor/illuminate/container/BoundMethod.php(29): call_user_func_array(Array, Array)
28 /var/www/vendor/illuminate/container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Containerclosure()
29 /var/www/vendor/illuminate/container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
30 /var/www/vendor/illuminate/container/Container.php(539): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
31 /var/www/vendor/illuminate/console/Command.php(182): Illuminate\Container\Container->call(Array)
32 /var/www/vendor/symfony/console/Command/Command.php(262): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\控制台\输出样式))
33 /var/www/vendor/illuminate/console/Command.php(167): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(照亮\控制台\输出样式))
34 /var/www/vendor/symfony/console/Application.php(888): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\控制台\输出\控制台输出))
35 /var/www/vendor/symfony/console/Application.php(224): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\ Console\Input\ArgvInput), 对象(Symfony\Component\Console\Output\ConsoleOutput))
36 /var/www/vendor/symfony/console/Application.php(125): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\组件\控制台\输出\控制台输出))
37 /var/www/vendor/laravel/lumen-framework/src/Console/Kernel.php(84): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput ), 对象(Symfony\Component\Console\Output\ConsoleOutput))
38 /var/www/artisan(35): Laravel\Lumen\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput) )
39 主要
这很奇怪,因为它不应该尝试创建 Pusher 实例。
我试过 composer dump-autoload、composer clear-cache、php artisan clear-compiled...
这很有趣,因为如果我尝试这段代码并转储实例,我会得到一个配置良好的 BroadcastManager:
$broadcastManager = (new BroadcastManager(app()))->connection();
有人可以帮忙吗?
【问题讨论】:
【参考方案1】:不要告诉你留言后发生了什么,试试看
composer require pusher/pusher-php-server --no-scripts
或
php artisan clear-compiled
或
编辑“vendor/laravel/framework/src/illuminate/Broadcasting/BroadcastManager.php”中的行
"使用推送器;" “使用 Pusher\Pusher;”
或
在您的 config/app.php 中将此行添加到别名
'Pusher' => Pusher\Pusher::class,
【讨论】:
在vendor/composer/autoload_classmap.php
我有'Pusher\\Pusher' => $vendorDir . '/pusher/pusher-php-server/src/Pusher.php',
所以,use Pusher\Pusher
是正确的。为什么我需要添加别名?以上是关于Laravel Lumen + Broadcasting + Redis + Class pusher not found的主要内容,如果未能解决你的问题,请参考以下文章