我正在使用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
但在查看调试控制台时,没有任何内容显示在pusher中。因此,似乎事件从未因某种原因被发送到推送器。我还检查了我的时区设置,以确保这不是问题。在广播事件时,我的laravel日志文件中没有错误。
我该如何解决这个问题?有没有一种好的方法来调试并查看是否确实有推送请求?
答案 0 :(得分:2)
这可能无法解决问题,也许您更改了问题的详细信息,但如果您的.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'),
],
它引用了代码中的值,而不是密钥!