3

Laravel 5.8

I am new to this whole pusher functionality and I've been following this tutorial and trying it out,

Create Web Notifications Using Laravel and Pusher Channels.

I've followed it step-by-step and when I get to the step to manually test the event by visiting the test url, I receive the following exception:

Illuminate \ Broadcasting \ BroadcastException No message

C:\wamp\www\ares\vendor\laravel\framework\src\Illuminate\Broadcasting\Broadcasters\PusherBroadcaster.php

Here is the code:

    $response = $this->pusher->trigger(
        $this->formatChannels($channels), $event, $payload, $socket, true
    );

    if ((is_array($response) && $response['status'] >= 200 && $response['status'] <= 299)
        || $response === true) {
        return;
    }

    throw new BroadcastException( // <-- Exception at this line
        is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']
    );
}

/**
 * Get the Pusher SDK instance.
 *
 * @return \Pusher\Pusher
 */
public function getPusher()
{
    return $this->pusher;
}
}

I've looked at a few other stack overflow articles which talk about changing encrypted: true to encrypted: false but that does not seem to affect anything.

Vikash Pathak
  • 3,444
  • 1
  • 18
  • 32
Jason Ayer
  • 621
  • 1
  • 10
  • 20

5 Answers5

5

I started working on Laravel 4 days ago and I came across this same problem when I was implementing a real-time chat application. After searching for many days, I discovered that this may vary depending on the version of Laravel you are running. If it is 5.8, you can fix this by adding the following code in the pusher.options array of the file config/broadcasting.php:

'curl_options' => [
                CURLOPT_SSL_VERIFYHOST => 0,
                CURLOPT_SSL_VERIFYPEER => 0,
            ],

After adding this , your pusher array in the config/broadcasting.php should look like this.

'pusher' => [
        'driver' => 'pusher',
        'key' => env('PUSHER_APP_KEY'),
        'secret' => env('PUSHER_APP_SECRET'),
        'app_id' => env('PUSHER_APP_ID'),
        'options' => [
            'cluster' => env('PUSHER_APP_CLUSTER'),
            'encrypted' => true,
            'curl_options' => [
                CURLOPT_SSL_VERIFYHOST => 0,
                CURLOPT_SSL_VERIFYPEER => 0,
            ],
        ],
    ],

You can then run php artisan config:cache(which may not be necessary in some cases) and finally run php artisan serve.You can consult your app in the pusher website and see the events you receive after sending your messages. Hope it helps!!

Joseph Joestar
  • 468
  • 1
  • 6
  • 11
  • @Dharman thanks for the advise! I was trying to get this to work but it turned out it was a local problem that I managed to solve with the link you provided. As I'm using Forge to manage my deployment, SSL config is already managed by Forge so the SSL connection works as expected without the need of this params in my server. Thanks again. – Kenny Horna Jun 21 '19 at 16:17
4

If you're working on localhost try setting your .env file.

Set:

APP_URL=http://localhost

DB_HOST=localhost

And run

php artisan config:cache
Franz
  • 354
  • 1
  • 4
  • 15
  • You should never cache your config in a local, development environment. [From the docs](https://laravel.com/docs/8.x/configuration#configuration-caching): *The command should not be run during local development as configuration options will frequently need to be changed during the course of your application's development.* If you've unintentionally cached your config locally, you more likely want [to clear those cached values](https://stackoverflow.com/a/53236811): `php artisan config:clear` – Don't Panic Aug 26 '21 at 09:41
0

Like i mentioned in a comment before this happens when the whole post goes wrong and wont deliver a response. Thats why the exception in line 116 is raised. I changed it to the domain before!

In my case i followed the code an found the method "createPusherDriver" in "vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php". At this place i inserted this

var_dump($config['key']);
var_dump($config['secret']);
var_dump( $config['app_id']);
var_dump($config['options']);
exit;

an noticed that my options still listed "host" => "localhost".

I removed those lines an cleared the config cache by executing php artisan config:cache

On next reload my event was fired an logged in the console.

C4pt4inC4nn4bis
  • 586
  • 1
  • 6
  • 18
0

Worked perfectly up to my Laravel 5.8 version. But encrypted' => true or encrypted' => false did not matter in this case for such Laravel version. But, following PUSHER suggestions, I put to broadcasting: 'useTLS' => true,.

This is the final result to me:

'options' => [
            'cluster' => env('PUSHER_APP_CLUSTER'),
            'encrypted' => true,
            'useTLS' => true,
            'curl_options' => [
                CURLOPT_SSL_VERIFYHOST => 0,
                CURLOPT_SSL_VERIFYPEER => 0,
            ],
        ]
Bitart
  • 73
  • 2
  • 7
0

Thanks to dear @Bitart

'useTLS' => true

option solved my issue.

'options' => [
     'cluster' => env('PUSHER_APP_CLUSTER'),
     'useTLS' => true,
]