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

elseloop's avatar

Reverb issues on deployed site

I have a single page on my site that uses Reverb. It is essentially a chat application, though framed as a collaborative poetry writing application. There are three components that use the websocket:

  1. the chat window:
    • this is the section of the page that displays the messages sent to the channel. There's an input field that takes in a message, a preview of the message visible as you're typing, and then an output area on the page for the message.
  2. A list of users currently connected to the channel
    • this is a simple list of users connected to the channel, showing avatars and names. It uses the same websocket as the chat window, but listens for different events (here, joining, leaving).
  3. A typing indicator
    • this is an indicator that shows "[user name] is typing..." to everyone else in the channel while a user is typing. It uses the same websocket as the chat window, but fires on and listens for a whisper event (typing).

Locally, everything works just fine. The odd thing that is happening when deployed to staging is that everything is working except the real time chat messages. The list of authors is updated and functions/updates as expected, the typing indicator also functions as expected, but the chat messages are not updating in real time. They are being saved in the database, as refreshing the page on the the receiving end shows the up-to-date messages.

Some applicable code

  1. The two useEffect calls connecting to Echo
    // typing indicator for other users
    useEffect(() => {
        if (lineValue.length > 0) {
            Echo.join(`corpse.${corpseCode}`).whisper('typing', {
                name: user.name,
            });
        }
    }, [lineValue, user.name, corpseCode]);

The applicable Controller method:

    public function update(Request $request, Corpse $corpse)
    {
        $request->validate([
            'text' => 'required',
        ]);

        $c = Corpse::find($corpse->id);

        $c->update([
            'title' => $request->title,
            'text' => $request->text,
        ]);

        broadcast(new CorpseUpdated($c))->toOthers();

        return to_route('corpse.show', $corpse);
    }

The CorpseUpdated broadcastOn method:

public function broadcastOn(): array
{
    return [
        new PresenceChannel('corpse.' . $this->corpse->id),
    ];
}

I have started a queue worker on the server and my .env file is set up correctly. I am at a loss as to what could be causing this issue. I have tried rebuilding my assets, etc, but that didn't help. I have also tried clearing the cache, but that didn't help either.

Any help would be greatly appreciated. Thanks!

0 likes
1 reply
LaryAI's avatar
Level 58

Based on the description of your issue, it seems like the real-time chat messages are not being updated on the client side, even though they are being saved in the database. This suggests that the issue might be related to the broadcasting setup or the client-side listening for the CorpseUpdated event.

Here are a few steps and checks you can perform to troubleshoot and potentially resolve the issue:

  1. Check Broadcasting Configuration:

    • Ensure that your broadcasting configuration in config/broadcasting.php is correctly set up for your environment (e.g., Pusher, Redis, etc.).
    • Verify that your .env file has the correct broadcasting driver and credentials.
  2. Verify Queue Configuration:

    • Since you mentioned starting a queue worker, ensure that your queue configuration is correct and that the queue worker is running without errors. You can check the logs for any queue-related errors.
  3. Check Event and Listener:

    • Ensure that the CorpseUpdated event is correctly set up to implement the ShouldBroadcast interface.
    • Double-check that the broadcastOn method is returning the correct channel.
  4. Client-Side Debugging:

    • Add console logs in the listen method for CorpseUpdated to ensure that the event is being received by the client.
    • Verify that the corpseCode variable is correctly set and matches the channel name used in the broadcastOn method.
  5. Network and Console Logs:

    • Use the browser's developer tools to check the network tab for any failed WebSocket connections or errors.
    • Look at the console for any JavaScript errors that might be preventing the event from being processed.
  6. Cross-Environment Differences:

    • Since the issue occurs only on the staging environment, compare the environment configurations between local and staging to identify any discrepancies.
  7. Rebuild and Clear Cache:

    • Although you've tried this, ensure that you have cleared all caches (php artisan cache:clear, php artisan config:clear, etc.) and rebuilt your assets (npm run prod or equivalent).
  8. Check WebSocket Server:

    • Ensure that your WebSocket server (e.g., Laravel Echo Server, Pusher) is running and accessible from your staging environment.

If after these checks the issue persists, you might want to add more detailed logging both on the server-side (in your event broadcasting logic) and on the client-side (in your JavaScript) to capture more information about what might be going wrong.

Please or to participate in this conversation.