Search code examples
phplaravellumenpusher

BroadcastException Pusher 404 Laravel/Lumen


The problem

For a Lumen 8 project we are trying to implement Pusher. We got it working locally in a Docker environment, but when we turn to Kubernetes it isn't working anymore. We get this error:

[2021-05-27 17:56:36] production.ERROR: Pusher error: 404 NOT FOUND {"exception":"[object] (Illuminate\\Broadcasting\\BroadcastException(code: 0): Pusher error: 404 NOT FOUND at /var/www/html/vendor/illuminate/broadcasting/Broadcasters/PusherBroadcaster.php:122)

Which means it throws on this piece of code:

114:         if ($this->pusherServerIsVersionFiveOrGreater()) {
115:             $parameters = $socket !== null ? ['socket_id' => $socket] : [];
116: 
117:             try {
118:                 $this->pusher->trigger(
119:                     $this->formatChannels($channels), $event, $payload, $parameters
120:                 );
121:             } catch (ApiErrorException $e) {
122:                 throw new BroadcastException(
123:                     sprintf('Pusher error: %s.', $e->getMessage())
124:                 );
125:             }
126:         }

The way it works is like this. The user triggers a function, which creates a Job which will be queued in Redis. Then when the Job is finished, the Event gets triggered.

The Jobs work, except for sending the events, which results in above error.

What we've tried

We tried adding Curl options to the Pusher broadcasting connection:

'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' => false,
                'curl_options' => [
                    CURLOPT_SSL_VERIFYHOST => 0,
                    CURLOPT_SSL_VERIFYPEER => 0,
                ]
            ],
        ],

And we tried changing the 'encrypted' option to true/false. None of these worked.

We tried to clear the cache with php artisan cache:clear as well as clearing it by hand rm -r storage/framework/cache.

We tried composer dump-autoloadand composer update.

We triple checked the Environment variables, but it still isn't working.

If you need any more info, let me know!


Solution

  • Okay, so this was a serious case of PEBKAC. Apparently we were using global .env variables but with a wrong name for the PUSHER APP ID. It should be fixed now that we changed the name of it.

    So if you get the 404 error, make sure that your app variables are right. Also make sure that the code can actually reach and read them. (You can do so with php artisan tinker).