Matkey Matkey - 7 months ago 27
PHP Question

Pusher not receiving events from Laravel 5.2 broadcasting

I am using Laravel 5.2 and php 7. I am testing this on a local Mac OSX environment. I am having no trouble pinging other services or making requests with php. I configured my application by editing broadcasting.php and .env with my api details.

broadcasting.php

'default' => env('BROADCAST_DRIVER', 'pusher'),

'connections' => [

'pusher' => [
'driver' => 'pusher',
'key' => env('mykey'),
'secret' => env('mysecret'),
'app_id' => env('myappid'),
],
...


and in .env

...
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=redis
BROADCAST_DRIVER=pusher

PUSHER_KEY=mykey
PUSHER_SECRET=mysecret
PUSHER_APP_ID=myappid
...


I created a TestEvent like so

<?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'];
}
}


I then call on the event like so

Event::fire(new TestEvent());


The event shows up and is processed in 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


But nothing shows up in pusher when viewing the debug console. So it seems that the event is never being sent to pusher for some reason. I also checked my timezone settings to make sure that was not an issue. There are no errors in my in the laravel log file when the event is broadcasted.

How can I solve this problem? Is there a good way to debug and see if there is actually a request being made to pusher?

Answer

This might not fix the issue and maybe you changed your details for the question, but if your .env is like this:

PUSHER_KEY=mykey
PUSHER_SECRET=mysecret
PUSHER_APP_ID=myappid

Shouldn't the code for your pusher credentials look like this:

'pusher' => [
        'driver' => 'pusher',
        'key' => env('PUSHER_KEY'),
        'secret' => env('PUSHER_SECRET'),
        'app_id' => env('PUSHER_APP_ID'),
    ],

It's referencing the value in your code, not the key!