Kaluna's avatar

Laravel Reverb, Payload too large?

Hey everyone.

I have a fairly in-complex Laravel app.

You can have a Journey, and within that Journey, you can have Phases, and within each phase, you can have a Task.

Each Task can have users assigned to them.

I'm using Laravel Reverb to live-update the Task "action" view (this is where the assigned user would "take" the task, and start working).

So, each Task has a user, but there's also an additional attribute, that makes them either a Technician, or a Reviewer. Each task can have many of either (for future scalability).

When I return my Task, after it's been updated, I am getting a Payload too large error.

Now, this particular Task, just has two users attached to it. Each Task only has 6/7 attributes, and same with the User model that is being returned.

I've increased the max_request_size value in config/reverb.php—but this doesn't appear to have had any impact at all.

One solution I thought of, was to break the broadcasts up, so, if you update a Task's reviewers or Technicians, it would only update that part of the UI.

However, I don't feel as though it's beyond the realms of possibility to just get all of the data I want to be packed via this websocket.

I've checked my model(s) for any erroneous with attributes, and, in some cases there are only one or two "Test" models, that belong to each Task (for context, a Task is either an "action", or a "test").

Has anybody experienced similar, and come up with a solution?

0 likes
1 reply
LaryAI's avatar
Level 58

Certainly! The "Payload too large" error in Laravel Reverb (or any websocket server) typically means the data you're broadcasting is exceeding the server's configured message size limit. Here are some steps and solutions to help you resolve this:


1. Double-Check max_request_size Configuration

You mentioned increasing max_request_size in config/reverb.php, but make sure:

  • You cleared your config cache after changing the value:
php artisan config:clear
php artisan cache:clear
  • The value is sufficiently large (e.g., 10240 for 10MB):
'max_request_size' => 10240,

2. Minimize Broadcast Payloads

Even if your models seem small, Eloquent relationships can cause unexpected data bloat, especially with nested relationships or hidden attributes. To control this:

  • Use Resource Classes for broadcasting:
// app/Http/Resources/TaskResource.php
use Illuminate\Http\Resources\Json\JsonResource;

class TaskResource extends JsonResource
{
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'status' => $this->status,
            // Only include what you need!
            'users' => UserResource::collection($this->users),
        ];
    }
}
  • In your event:
public function broadcastWith()
{
    return (new TaskResource($this->task))->toArray(request());
}

3. Check for Unintended Eager Loading

If you have a global or local with() on your Task model, you might be loading more than you realize. Double-check your model:

protected $with = []; // Make sure this is empty or only includes what you need

4. Consider Broadcasting Only Changed Data

If you only need to update a small part of the UI, consider broadcasting only the changed attributes or relationships, not the entire Task model.

public function broadcastWith()
{
    return [
        'task_id' => $this->task->id,
        'updated_field' => $this->task->status, // or whatever changed
    ];
}

5. Debug the Actual Payload Size

You can log the payload size before broadcasting to see what’s actually being sent:

$payload = (new TaskResource($this->task))->toArray(request());
\Log::info('Broadcast payload size: ' . strlen(json_encode($payload)));

6. Check Client-Side Code

Sometimes, the client might be sending large payloads back to the server (e.g., via Echo or custom websocket messages). Make sure only necessary data is sent.


7. Restart Reverb

After changing config, restart the Reverb server:

php artisan reverb:restart

Summary

  • Use resource classes to control broadcasted data.
  • Double-check and clear config cache after changing max_request_size.
  • Avoid unnecessary eager loading.
  • Broadcast only what’s needed.
  • Log and inspect actual payload sizes.
  • Restart Reverb after config changes.

If after all this you’re still hitting the limit, please post your event’s broadcastWith() method and any relevant model relationships for further help!

Please or to participate in this conversation.