我正在使用Laravel 5.2和php 7.我在本地Mac OSX环境中测试它.我没有麻烦ping其他服务或用
PHP发出请求.我通过使用api详细信息编辑broadcast.php和.env来配置我的应用程序.
broadcasting.php
'default' => env('BROADCAST_DRIVER', 'pusher'),
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('mykey'),
'secret' => env('mysecret'),
'app_id' => env('myappid'),
],
...
并在.env
...
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=redis
BROADCAST_DRIVER=pusher
PUSHER_KEY=mykey
PUSHER_SECRET=mysecret
PUSHER_APP_ID=myappid
...
我这样创建了一个TestEvent
<?php
namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class TestEvent extends Event implements ShouldBroadcast
{
use SerializesModels;
public $data;
public function __construct()
{
$this->data = array(
'power'=> '10'
);
}
public function broadcastOn()
{
return ['test_channel'];
}
}
然后我就这样打电话
Event::fire(new TestEvent());
该事件显示并以redis处理
[2016-02-04 10:06:18] Processed: Illuminate\Broadcasting\BroadcastEvent
[2016-02-04 10:08:44] Processed: Illuminate\Broadcasting\BroadcastEvent
[2016-02-04 10:11:14] Processed: Illuminate\Broadcasting\BroadcastEvent
[2016-02-04 10:11:59] Processed: Illuminate\Broadcasting\BroadcastEvent
[2016-02-04 10:14:22] Processed: Illuminate\Broadcasting\BroadcastEvent
[2016-02-04 11:17:04] Processed: Illuminate\Broadcasting\BroadcastEvent
[2016-02-04 11:38:14] Processed: Illuminate\Broadcasting\BroadcastEvent
但是在查看调试控制台时,没有任何东西出现在推动器中.因此,似乎事件从未因某种原因被发送到推送器.我还检查了我的时区设置,以确保这不是问题.广播事件时,我在laravel日志文件中没有错误.
我怎么解决这个问题?有没有一种好的方法来调试并查看是否实际上有一个请求被推送?
最佳答案 这可能无法解决问题,也许您更改了问题的详细信息,但如果您的.env是这样的:
PUSHER_KEY=mykey
PUSHER_SECRET=mysecret
PUSHER_APP_ID=myappid
您的推送凭据的代码不应该如下所示:
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_KEY'),
'secret' => env('PUSHER_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
],
它引用了代码中的值,而不是密钥!