Framework: PusherBroadcaster exception "Failed to connect to Pusher" when running in queue

Created on 19 Nov 2016  Â·  26Comments  Â·  Source: laravel/framework

  • Laravel Version: 5.3.23
  • PHP Version: 5.6.15
  • Database Driver & Version: MySql 5.6.31
  • OS : Windows 8.1 64bits

Description:

I'm using the "broadcast" notification channel to notify the user via pusher.

When not using queue or using queue with the sync driver every thing works as expected, and i receive the notification.
But when i use the database driver for queues, the app can't connect to pusher.
This is the log.

local.ERROR: exception 'Illuminate\Broadcasting\BroadcastException' with message 'Failed to connect to Pusher.' in F:\wamp3\www\opendata\vendor\laravel\framework\src\Illuminate\Broadcasting\Broadcasters\PusherBroadcaster.php:105
Stack trace:
#0 F:\wamp3\www\opendata\vendor\laravel\framework\src\Illuminate\Broadcasting\BroadcastEvent.php(53): Illuminate\Broadcasting\Broadcasters\PusherBroadcaster->broadcast(Array, 'Illuminate\\Noti...', Array)
#1 F:\wamp3\www\opendata\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(73): Illuminate\Broadcasting\BroadcastEvent->fire(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#2 F:\wamp3\www\opendata\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(201): Illuminate\Queue\Jobs\Job->fire()
#3 F:\wamp3\www\opendata\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(152): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#4 F:\wamp3\www\opendata\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(76): Illuminate\Queue\Worker->runNextJob('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#5 F:\wamp3\www\opendata\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(101): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#6 F:\wamp3\www\opendata\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(85): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#7 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#8 F:\wamp3\www\opendata\vendor\laravel\framework\src\Illuminate\Container\Container.php(508): call_user_func_array(Array, Array)
#9 F:\wamp3\www\opendata\vendor\laravel\framework\src\Illuminate\Console\Command.php(169): Illuminate\Container\Container->call(Array)
#10 F:\wamp3\www\opendata\vendor\symfony\console\Command\Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 F:\wamp3\www\opendata\vendor\laravel\framework\src\Illuminate\Console\Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 F:\wamp3\www\opendata\vendor\symfony\console\Application.php(820): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 F:\wamp3\www\opendata\vendor\symfony\console\Application.php(187): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 F:\wamp3\www\opendata\vendor\symfony\console\Application.php(118): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 F:\wamp3\www\opendata\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(121): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 F:\wamp3\www\opendata\artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 {main}  

Edit: I'm also using the mail and database channels in the same notification.
These two always work, even from the queue with database driver.

Most helpful comment

A bit late, but you could just disable the encrypted options.

'options' => [
    'cluster' => 'eu',
    'encrypted' => false
]

So pusher will allow http calls but it's not recommended for production use.

All 26 comments

Have you solved this issue? If so, mind explaining it? I am getting the same error trying to broadcast with pusher. I have tried both database and sync queue drivers or no queue at all, prefer not to use others. Frontend with javascript works fine, tested with pushers event creator. I have set the correct pusher app details in the .env file, additional cluster option set aswell. Broadcast channel is set to public.
Am I missing something that's not documented?

  • Laravel Version: 5.3.23
  • PHP Version: 7.0 on both Windows and Ubuntu
  • Database Driver & Version: MySQL 5.6 and 5.7

`local.ERROR: Illuminate\Broadcasting\BroadcastException: Failed to connect to Pusher. in C:\xampp\htdocspusher\vendor\laravel\framework\src\Illuminate\Broadcasting\Broadcasters\PusherBroadcaster.php:105
Stack trace:

0 C:\xampp\htdocspusher\vendor\laravel\framework\src\Illuminate\Broadcasting\BroadcastEvent.php(52): Illuminate\Broadcasting\Broadcasters\PusherBroadcaster->broadcast(Array, 'App\Events\NewC...', Array)

1 C:\xampp\htdocspusher\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(73): Illuminate\Broadcasting\BroadcastEvent->fire(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)

2 C:\xampp\htdocspusher\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(201): Illuminate\Queue\Jobs\Job->fire()

3 C:\xampp\htdocspusher\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(150): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))

4 C:\xampp\htdocspusher\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(100): Illuminate\Queue\Worker->runNextJob('database', 'default', Object(Illuminate\Queue\WorkerOptions))

5 C:\xampp\htdocspusher\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(83): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')

6 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()

7 C:\xampp\htdocspusher\vendor\laravel\framework\src\Illuminate\Container\Container.php(508): call_user_func_array(Array, Array)

8 C:\xampp\htdocspusher\vendor\laravel\framework\src\Illuminate\Console\Command.php(169): Illuminate\Container\Container->call(Array)

9 C:\xampp\htdocspusher\vendor\symfony\console\Command\Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

10 C:\xampp\htdocspusher\vendor\laravel\framework\src\Illuminate\Console\Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

11 C:\xampp\htdocspusher\vendor\symfony\console\Application.php(820): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

12 C:\xampp\htdocspusher\vendor\symfony\console\Application.php(187): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

13 C:\xampp\htdocspusher\vendor\symfony\console\Application.php(118): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

14 C:\xampp\htdocspusher\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(121): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

15 C:\xampp\htdocspusher\artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

16 {main}`

Yeah i solved it, you need to download curl certificate and point to it in your php.ini

When sending data to pusher, using the sync queue driver or no queue at all the php.ini file within your apache installation will be used. Because your request is coming from the web server. (HTTP)

When sending data to pusher, using any other queue driver the php.ini within php installation will be used. Because your request is coming from the console.

For me, the problem was that i added the certificate in the php.ini used by apache server, and didn't add it in php.ini within the php.x.x.x/bin, so you just need to make sure that your add the certificate in both php.ini files.

You can download the certificate from https://curl.haxx.se/ca/cacert.pem

Then in both php.ini files search for this curl.cainfo and set the value to where your certificate is

For me it's something like this :

[curl]
curl.cainfo = "F:\wamp3\bin\php\php5.6.15\extras\ssl\cacert.pem"

I got the same exception. But for me it was the timestamp on Homestead. This solved it: https://support.pusher.com/hc/en-us/articles/202046573-How-to-fix-Timestamp-expired-response-from-REST-API-when-triggering-an-event-

A bit late, but you could just disable the encrypted options.

'options' => [
    'cluster' => 'eu',
    'encrypted' => false
]

So pusher will allow http calls but it's not recommended for production use.

I have same issue, and solved with
sudo ntpdate ntp.ubuntu.com

@cre8 thanx man. had been stuck for whole day bec. of this.

Hello.

I have the same problem, I am using linux mint and I have been trying to fix the error for some time and I have not been able to.

Thank's

@cre8 It works now, Thanks

Got mine working by adding ssl certificate as @shadoWalker89 said.

please, how do I add the SSL certificate on Heroku? Already tried created a .user.ini file as specified, added the file to my root directory, specified the curl.cainfo and pushed to Heroku as specified customize Heroku PHP settings but it still doesn't work.

I'm facing the same issue. Is there any way to make this work with encrypted=true ?

@TheBigK install the certificate
https://github.com/laravel/framework/issues/16478#issuecomment-261796182

@shadoWalker89 - I already have the LetsEncrypt certificates installed and working. I got this working without SSL (by disabling all certificate checks); but still have no clue how to make it work with SSL and encryption turned on.

I did try with curl.cainfo in php.ini. Could you tell me if I should put it in php.ini inside cli or fpm?

@shadoWalker89 - I tried adding the info to php.ini inside the 'fpm'. Which is the other location you are talking about?

How to Fix Failed to connect to Pusher when using Laravel Valet with Php7.2 or above On Mac
———————————————————————————————————------------------

NB: I decided to write this because I don’t think anyone else should spend 5 hours fixing this, I have already done that. 


Server : Valet

OS: Mac Mojave

PHP Version: 7.2

In my case turning forceTLS to false worked but I did not like that solution. 
Also adding:

'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
]
to my broadcasting.php file worked but for some reason I was not convinced with this solution too. 



  1. So I decided to make things work by downloading the CA bundle from https://curl.haxx.se/ca/cacert.pem and moved the cacert.pem from the downloads folder into /usr/local/etc/[email protected]/certs (in my case I installed openssl1.1 using homebrew only because I was trying various things I find online just to make this work but now I know I do not need openssl1.1 you may go with the openssl folder you already have) so the full path to the cacert file becomes /usr/local/etc/[email protected]/certs/cacert.pem 



Opening php.ini

——————---

  1. From your terminal enter php --ini to find the path to the loaded php.ini (open that in your editor of choice; I use nano sometimes)
Important: As of PHP 7.2 (Win 64) this directive, will NOT show in the phpinfo() even though it's set. (In comparison, an openssl.cafile directive will show, if it's set to the exact same path).

  2. So now in your php.ini set the following to : (NB: replace the path to indicate where those files can be found on your system) 
openssl.cafile = “/usr/local/etc/[email protected]/certs/cacert.pem’
openssl.capath = “/usr/local/etc/[email protected]/certs”
Take note: because I am using php7.2 I did not have to set curl.cainfo to anything; initially I spent so many hours trying to use curl.info method which did not work for me so in my final configuration I commented it by putting a semi-colon in front of it ( ;curl.cainfo ="/usr/local/etc/[email protected]/certs/cacert.pem”)

  3. After this you should run valet restart which would restart some valet services but I realised even after valet restarts, my new php.ini changes are not reflecting when I do phpinfo();

  4. Finally you should restart php by entering brew services restart php72 (NB: I installed php via homebrew so incase you did not , you would have to restart php differently)

Hope this helps . Even if does not solve your problem exactly it would surely give you some ideas to try out just as I leveraged other peoples tiny bits of ideas from one page to another in coming up with my solution.

Hello, I had the same issue, I even tried setting encrypted to false, php artisan config:cache; php artisan route:cache; but still have the same error.
Any help?

@mariembenslama have you tried the post above ?

I have fedora 29, and I couldn't find the php.ini file; yes I did (the encrypted = false solution)

I have fedora 29, and I couldn't find the php.ini file
You would have to find the php.ini , what output does your terminal give when you do PHP --ini

PHP

Yes I found it in /etc/ ^^ I'll try the solution and tell you

@hinimajesty I add curl.cainfo = "\home\mariembenslama\Documents\certificate\cacert.pem"
to php.ini, after downloading the certificate, but still get the same error (this time the header Broadcast not found 404 doesn't appear, but it's still the same error)

Illuminate\Broadcasting\BroadcastException
throw new BroadcastException(
is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']
);

@mariembenslama what version of php are you using ? Please refer to this https://github.com/laravel/framework/issues/16478#issuecomment-615307814

It's PHP 7.2.24, yes you are right it's not the same.

Capture d’écran de 2020-04-18 11-28-02

@mariembenslama this comment should help you https://github.com/laravel/framework/issues/16478#issuecomment-615307814
So try it out fully. You may have to change some directory paths but certainly, ideas from this would go a long way in helping; that is if the issue you are having is as a result of curl not correctly verifying the host from which the secured request to pushers servers is coming from.

Screenshot 2020-04-18 at 10 39 11 AM
You can setup a dummy route and check phpinfo and see if the cafile and path is set correctly like it says in the comment #16478

So in my case in the web.php file i do Route::get('/info', function(){ phpinfo(); }) just to ensure php is picking the settings from the php.ini file.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jackmu95 picture jackmu95  Â·  3Comments

CupOfTea696 picture CupOfTea696  Â·  3Comments

lzp819739483 picture lzp819739483  Â·  3Comments

iivanov2 picture iivanov2  Â·  3Comments

JamborJan picture JamborJan  Â·  3Comments