The other day I was getting some hands-on experience with Laravel 5.1’s event broadcasting features. I followed all the requirements specified by the documentation. However, when my application would broadcast the event, it would not reach Pusher.
During my debugging process I confirmed that:
- I had Pusher’s composer package pulled into my app.
- I was using the proper api keys provided by Pusher.
- My event class implemented Illuminate\Contracts\Broadcasting\ShouldBroadcast contract
- My event class used the Illuminate\Queue\SerializesModels trait.
- My event was firing the event that was to be broadcasted.
- That my broadcast was being sent out through the queue.
At this point my brain is screaming “WTF?”
I decided to go into the source code of Pusher’s composer package. I placed a var dump inside the exec_curl() private function which then spit back the following:
[body] => Timestamp expired: Given timestamp (2015-06-15T03:30:47Z) not within 600s of server time (2015-06-15T03:41:33Z) [status] => 401
Ah hah, now we’re on to something.
I took to the web to see what I could find which led me to this stack overflow topic. This began to make sense. If you ever worked with Windows Domain Controllers there is a Kerberos Authentication process that is reliant on a NTP (network time protocol) threshold. Well the same can be said for Linix/Unix when it came to how Pusher authenticates requests. I took the command mentioned on Stack Overflow and ran it inside of Homestead:
sudo ntpdate ntp.ubuntu.com
And as you would expect it fixed the problem entirely. I’m sure some other Homestead users will more than likely encounter this problem at some point. So enjoy the solution