Skip to main content

Laravel Reverb WebSockets Implementation

Implement real-time features with Laravel Reverb including presence channels, private channels, client events, and scalable WebSocket broadcasting.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
Implement a real-time collaborative document editing with live cursors and presence feature using Laravel Reverb in a team project management platform application. The feature needs to support 500 concurrent connections and broadcasts 100 events per second at peak events. Use Laravel 11 with Reverb. Build it step by step: 1) Install and configure Reverb: set up the Reverb server configuration in config/broadcasting.php, configure the WebSocket transport, set max_request_size for 64KB payloads, define the app credentials, and add the necessary environment variables. Configure the Vite plugin for the Echo client with Reverb connection parameters. 2) Create 6 broadcast events: for each event, define the broadcastOn() channel (public, private, or presence), broadcastWith() payload optimized to under 10KB bytes, broadcastAs() with a semantic name, and implement ShouldBroadcastNow vs. ShouldBroadcast based on latency requirements. Model events: DocumentUpdated, CursorMoved, UserJoinedDocument, UserLeftDocument, CommentAdded, DocumentLocked. 3) Implement channel authorization: define 4 channel routes in routes/channels.php — for private channels, verify the user has permission to join based on team membership and document access permissions. For presence channels, return user info (id, name, avatar) and implement joining/leaving callbacks on the frontend. 4) Build the frontend real-time listeners using Laravel Echo: initialize Echo with the Reverb connector, subscribe to channels, listen for events, and update the UI reactively. Handle reconnection on connection drop, show a connection status indicator, and implement yes, for text edits and cursor positions optimistic UI updates that reconcile with server confirmations. 5) Add client events for typing indicators and cursor position sharing: enable client events on the presence channel, implement rate limiting of 10 events per second per user, validate client event payloads, and handle the whisper/listenForWhisper pattern for ephemeral events. 6) Scale for production: configure Reverb to run as a supervised process using Supervisor, set up Redis pub/sub for multi-server Reverb instances behind a load balancer for horizontal scaling, implement connection limits per user (5 (multiple tabs/devices)), and add monitoring for active connections, message throughput, and memory usage. 7) Write feature tests: use the BroadcastFake and Event::fake() to test event dispatching, channel authorization, and payload structure without a running Reverb server.

What this prompt does

This prompt makes the AI implement a real-time [feature_type] feature on Laravel Reverb, scoped by [concurrent_users] connections and [event_frequency] on Laravel [laravel_version]. It walks the full path: configuring Reverb and the Echo client, defining [event_count] broadcast events, wiring channel authorization, building the frontend listeners, adding client events, and scaling for production. Because you declare the connection count and event rate, the AI sizes payloads and scaling instead of producing a demo that only works for one user.

The structure works because real-time fails in the details this prompt forces you to specify. [max_payload_size] and [payload_limit] constrain message size; [event_list] and [channel_count] define the channels and their authorization via [auth_logic]; [client_event_limit] rate-limits whispers for typing indicators; and [process_manager], [horizontal_scaling], and [max_connections_per_user] cover supervised processes and multi-server scaling. The final step asks for tests using BroadcastFake and Event::fake() so the channels stay honest without a running server. Each broadcast event also gets a broadcastWith() payload trimmed under [payload_limit] and a choice between ShouldBroadcastNow and ShouldBroadcast based on how latency-sensitive that event is. Declaring [concurrent_users] and [event_frequency] is what lets the AI reason about message size and queueing instead of broadcasting everything synchronously, and the [reverb_transport] and [max_payload_size] settings keep the server configured for the traffic you actually expect.

When to use it

  • You are adding collaborative editing, live cursors, or presence to a Laravel app
  • You need presence channels that report who joined and left in real time
  • You want typing indicators or cursor sharing via client events with rate limiting
  • You expect hundreds of concurrent connections and must plan horizontal scaling
  • You want optimistic UI updates that reconcile against server confirmations
  • You need feature tests for broadcasting without standing up a live Reverb server

Example output

The AI returns step-by-step Laravel code: Reverb and broadcasting config, Echo client setup via Vite, a set of broadcast event classes with broadcastOn(), broadcastWith(), and broadcastAs(), channel routes in routes/channels.php with private and presence authorization, frontend Echo listeners with reconnection handling and a connection-status indicator, client-event whisper handling, a Supervisor and Redis pub/sub scaling plan, and feature tests using BroadcastFake.

Pro tips

  • Keep [payload_limit] well under [max_payload_size]; lean payloads are what hold up at [event_frequency]
  • Choose ShouldBroadcastNow only for latency-critical events — broadcasting everything synchronously can starve your workers
  • Set [client_event_limit] deliberately; unthrottled typing/cursor whispers flood the channel under load
  • Spell out [auth_logic] precisely so private and presence channels reject users who lack access
  • Use [max_connections_per_user] to account for multiple tabs and devices, not just one session
  • Lean on BroadcastFake and Event::fake() in tests — presence and client events are easy to break silently
  • Configure reconnection handling and a connection-status indicator early so dropped sockets recover instead of silently going stale
  • Match [max_payload_size] to your largest realistic event so the transport is not undersized for collaborative edits

Frequently Asked Questions

Can I test Reverb broadcasting without running the Reverb server?
Yes. The final step uses BroadcastFake and Event::fake() to assert event dispatching, channel authorization, and payload structure in tests. This keeps presence and client-event logic covered without standing up a live WebSocket server in CI.
How does it handle typing indicators and cursor sharing?
Those are built as client events (whispers) on the presence channel, with rate limiting set by `[client_event_limit]` events per second per user. The prompt asks for payload validation and the whisper/listenForWhisper pattern so ephemeral events do not hit your server unnecessarily.
Does it cover scaling Reverb across multiple servers?
It configures Reverb as a supervised process using `[process_manager]` and sets up `[horizontal_scaling]`, defaulting to Redis pub/sub across multiple Reverb instances behind a load balancer. It also caps connections per user via `[max_connections_per_user]`.
What is the difference between ShouldBroadcast and ShouldBroadcastNow here?
The prompt asks you to choose per event based on latency needs. ShouldBroadcastNow sends synchronously for time-sensitive events like cursor moves, while ShouldBroadcast queues the broadcast, which is fine for less urgent updates and easier on your workers under load.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Laravel & PHP Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support