Laravel Reverb promises native WebSocket support without external services like Pusher or Ably. Self-hosted real-time capabilities reduce costs and dependencies. At ZIRA Software, we're excited about first-party WebSocket infrastructure.
Why Reverb Matters
Current options:
- Pusher: Easy but costly at scale
- Socket.io: Requires separate Node server
- Laravel WebSockets: Community package, maintenance concerns
Reverb benefits:
- Official Laravel package
- No external services
- Horizontal scaling support
- Native integration with Echo
Expected Architecture
┌─────────────────┐ ┌─────────────────┐
│ Laravel App │────▶│ Reverb Server │
│ (HTTP + API) │ │ (WebSocket) │
└─────────────────┘ └────────┬────────┘
│
┌────────────┼────────────┐
│ │ │
▼ ▼ ▼
Client 1 Client 2 Client 3
Broadcasting Setup (Preview)
// config/broadcasting.php
'connections' => [
'reverb' => [
'driver' => 'reverb',
'app_id' => env('REVERB_APP_ID'),
'key' => env('REVERB_APP_KEY'),
'secret' => env('REVERB_APP_SECRET'),
'host' => env('REVERB_HOST', 'localhost'),
'port' => env('REVERB_PORT', 8080),
'scheme' => env('REVERB_SCHEME', 'http'),
],
],
# .env
BROADCAST_DRIVER=reverb
REVERB_APP_ID=my-app
REVERB_APP_KEY=my-key
REVERB_APP_SECRET=my-secret
REVERB_HOST=localhost
REVERB_PORT=8080
Events and Broadcasting
// app/Events/MessageSent.php
class MessageSent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public function __construct(
public Message $message,
public User $user,
) {}
public function broadcastOn(): array
{
return [
new PrivateChannel('chat.' . $this->message->conversation_id),
];
}
public function broadcastWith(): array
{
return [
'id' => $this->message->id,
'content' => $this->message->content,
'user' => [
'id' => $this->user->id,
'name' => $this->user->name,
],
'sent_at' => $this->message->created_at->toISOString(),
];
}
}
Laravel Echo Integration
// resources/js/bootstrap.js
import Echo from 'laravel-echo';
window.Echo = new Echo({
broadcaster: 'reverb',
key: import.meta.env.VITE_REVERB_APP_KEY,
wsHost: import.meta.env.VITE_REVERB_HOST,
wsPort: import.meta.env.VITE_REVERB_PORT,
forceTLS: false,
enabledTransports: ['ws', 'wss'],
});
// Listening to events
Echo.private(`chat.${conversationId}`)
.listen('MessageSent', (e) => {
console.log('New message:', e.message);
appendMessage(e);
})
.listenForWhisper('typing', (e) => {
showTypingIndicator(e.user);
});
// Sending client events
Echo.private(`chat.${conversationId}`)
.whisper('typing', {
user: currentUser.name
});
Presence Channels
// routes/channels.php
Broadcast::channel('chat.{conversationId}', function ($user, $conversationId) {
if ($user->canAccessConversation($conversationId)) {
return [
'id' => $user->id,
'name' => $user->name,
'avatar' => $user->avatar_url,
];
}
});
// Frontend presence handling
Echo.join(`chat.${conversationId}`)
.here((users) => {
setOnlineUsers(users);
})
.joining((user) => {
addOnlineUser(user);
})
.leaving((user) => {
removeOnlineUser(user);
});
Expected Scaling Strategy
# docker-compose.yml for horizontal scaling
services:
app:
image: laravel-app
deploy:
replicas: 3
reverb:
image: laravel-reverb
deploy:
replicas: 2
environment:
- REVERB_SCALING_DRIVER=redis
- REDIS_HOST=redis
redis:
image: redis:alpine
nginx:
image: nginx
ports:
- "80:80"
- "8080:8080"
Current Alternatives
While waiting for Reverb, use these solutions:
# Laravel WebSockets (community package)
composer require beyondcode/laravel-websockets
# Soketi (open-source Pusher alternative)
npm install -g @soketi/soketi
soketi start
Conclusion
Laravel Reverb will provide official WebSocket support for self-hosted real-time applications. The integration with Echo and broadcasting events promises seamless adoption.
Need real-time features now? Contact ZIRA Software for WebSocket implementation.