Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

longestdrive's avatar

Responding to Pusher Events across Livewire components failing on staging server

I've been able to set up pusher and send, receive and respond to events on my local machine (docker using Laravel Sail). Each Livewire component across different pages responds to the event from pusher and does it's thing!

However, on my staging server only one component is responding to the event. The other fails to respond even though it appears the livewire component's event listener is configured the same. It fails whether I'm logged in as the same user (with 2 x browser tabs open to the page) or different users logged in from different devices.

in bootstrap.js I have:

import Echo from 'laravel-echo';

import Pusher from 'pusher-js';

window.Pusher = Pusher;

window.Pusher.logToConsole = true;

window.Echo = new Echo({
  broadcaster: 'pusher',
  key: import.meta.env.VITE_PUSHER_APP_KEY,
  cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER,
  forceTLS: true
});

In app.js I have

document.querySelector('#submit-button').addEventListener(
  'click',
  () => window.axios.post('/button/clicked')
);

// Subscribe to the public channel called "public-channel"
Echo.channel('golfbuddies-tour-development')

  // Listen for the event called "button.clicked"
  .listen('.ButtonClicked', (e) => {
    console.log('event received:1', e);
  });

I've added a button to fire the event whilst trying to debug this issue.

I've checked my .env and have all the correct pusher credentials set up on the local and staging server. I can see from the console pusher events are being sent and received (and I know one component is responding to the event.

This is the abridged version of the working component:

and this is an abridged version of the non-working component (that does work on the local machine)

and the Laravel event:

I've removed the real channel name but have checked it's consistent. I've commented out the broadcastAs() as that caused an error earlier in development but should not be related to the issue.

In my console I see:

Pusher :  : ["Event recd",{"event":"App\\Events\\ButtonClicked","channel":"channel-name","data":{"message":"Hello world!"}}]

My log file only shows the event message from Livescore component

I'm not sure what could be different on each server (local and staging) to create this issue. I see no errors in the log file and can see messages that the event is fired. I can also see the job being processed by Horizon on the staging server.

Where to start to get all components working and responding to the event?

0 likes
2 replies
LaryAI's avatar
Level 58

To troubleshoot and resolve the issue where only one Livewire component is responding to Pusher events on your staging server, you can follow these steps:

  1. Check Channel Subscription: Ensure that both components are subscribing to the correct channel. Double-check the channel name in both components and make sure they match exactly with the channel name used in the broadcastOn() method of your event.

  2. Verify Event Listener Configuration: Confirm that the event listeners in both components are correctly set up. The listener should match the event name being broadcasted. Since you commented out broadcastAs(), the event name defaults to the class name, which is App\Events\ButtonClicked. Ensure your listener is configured to listen for this event.

    protected $listeners = ['echo:channel-name,App\\Events\\ButtonClicked' => 'updateLeaderboard'];
    
  3. Check Pusher Configuration: Verify that your Pusher credentials and configuration are correct on the staging server. Ensure that the VITE_PUSHER_APP_KEY, VITE_PUSHER_APP_CLUSTER, and other related environment variables are correctly set in your .env file on the staging server.

  4. Console Logs: Since you have window.Pusher.logToConsole = true;, check the browser console for any errors or warnings related to Pusher. This can provide insights into whether the events are being received and if there are any issues with the connection.

  5. Network and Firewall: Ensure that there are no network or firewall restrictions on the staging server that might be blocking Pusher connections. Pusher uses WebSockets, which might be blocked by some network configurations.

  6. Debugging Logs: Add additional logging in your Livewire components to see if the event listener is being triggered. This can help determine if the issue is with the event not being received or with the logic inside the listener.

    public function updateLeaderboard()
    {
        Log::info('updateLeaderboard called in Livescore component');
        // existing logic
    }
    
  7. Check for JavaScript Errors: Ensure there are no JavaScript errors on the page that might be preventing the event listener from working correctly. JavaScript errors can sometimes halt the execution of subsequent scripts.

  8. Cross-Check with Local Setup: Compare the setup on your local environment with the staging environment. Look for any discrepancies in configuration files, package versions, or server settings.

By following these steps, you should be able to identify and resolve the issue with the Livewire components not responding to Pusher events on your staging server. If the problem persists, consider reaching out to the community with specific logs or errors for further assistance.

Please or to participate in this conversation.