pusher / pusher-http-php

PHP library for interacting with the Pusher Channels HTTP API
https://pusher.com/docs/server_api_guide
1.42k stars 309 forks source link

BroadcastException Pusher 404 Laravel/Lumen #308

Closed jordyvanvijfeijken closed 3 years ago

jordyvanvijfeijken commented 3 years ago

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-autoload and composer update.

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

I don't know of this should be here, already asked on SO, but didn't get an answer. I hope someone can help us out.

jordyvanvijfeijken commented 3 years ago

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. Sorry!