Kritim Yantra
Apr 05, 2025
Real-time communication is a crucial feature for modern web applications, enabling instant updates, live notifications, and interactive user experiences. With the release of Laravel 12, the framework introduces Laravel Reverb, a powerful WebSocket server designed to provide blazing-fast, scalable real-time communication directly within Laravel applications.
Reverb seamlessly integrates with Laravel’s existing event broadcasting system, allowing developers to build real-time features without relying on third-party services like Pusher or Soketi. In this blog, we’ll explore what Laravel Reverb is, how to set it up, configure it for production, and scale it efficiently.
Laravel Reverb is a first-party WebSocket server built specifically for Laravel applications. It enables bi-directional communication between the server and clients (browsers, mobile apps, etc.) using the WebSocket protocol.
✅ Native Integration – Works seamlessly with Laravel’s event broadcasting.
✅ High Performance – Built on ReactPHP for handling thousands of concurrent connections.
✅ Scalability – Supports horizontal scaling via Redis pub/sub.
✅ Security – Supports SSL, origin restrictions, and application authentication.
✅ Monitoring – Integrates with Laravel Pulse for real-time metrics.
Setting up Reverb is straightforward. Run the following Artisan command:
php artisan install:broadcasting
This command installs Reverb and generates a default configuration in config/reverb.php
.
Reverb requires application credentials to authenticate WebSocket connections. Define these in your .env
file:
REVERB_APP_ID=my-app-id
REVERB_APP_KEY=my-app-key
REVERB_APP_SECRET=my-app-secret
To prevent unauthorized connections, specify allowed origins in config/reverb.php
:
'apps' => [
[
'app_id' => 'my-app-id',
'allowed_origins' => ['laravel.com'],
],
]
Use '*'
to allow all origins (not recommended for production).
Reverb can serve multiple applications from a single server:
'apps' => [
['app_id' => 'app-one'],
['app_id' => 'app-two'],
],
Start the server with:
php artisan reverb:start
php artisan reverb:start --host=127.0.0.1 --port=9000
Or define in .env
:
REVERB_SERVER_HOST=0.0.0.0
REVERB_SERVER_PORT=8080
Enable debug logs with:
php artisan reverb:start --debug
For secure WebSocket connections (wss://
), Reverb supports SSL via:
config/reverb.php
):'options' => [
'tls' => [
'local_cert' => '/path/to/cert.pem',
],
],
Since Reverb runs as a long-lived process, use Supervisor to keep it running:
[program:reverb]
command=php artisan reverb:start
autostart=true
autorestart=true
user=forge
minfds=10000 # Increase open file limit
Configure Nginx to proxy WebSocket traffic:
location / {
proxy_pass http://0.0.0.0:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
WebSocket connections consume file descriptors. Increase system limits:
# Check current limit
ulimit -n
# Increase limit (e.g., 10,000)
echo "forge soft nofile 10000" >> /etc/security/limits.conf
echo "forge hard nofile 10000" >> /etc/security/limits.conf
Update /etc/nginx/nginx.conf
:
worker_rlimit_nofile 10000;
events {
worker_connections 10000;
}
For high-traffic apps, run multiple Reverb servers behind a load balancer:
.env
:REVERB_SCALING_ENABLED=true
Track connections & messages in real-time:
composer require laravel/pulse
php artisan pulse:install
config/pulse.php
):use Laravel\Reverb\Pulse\Recorders\ReverbConnections;
use Laravel\Reverb\Pulse\Recorders\ReverbMessages;
'recorders' => [
ReverbConnections::class => ['sample_rate' => 1],
ReverbMessages::class => ['sample_rate' => 1],
],
<x-pulse>
<livewire:reverb.connections cols="full" />
<livewire:reverb.messages cols="full" />
</x-pulse>
Laravel Reverb is a game-changer for real-time Laravel applications. With native WebSocket support, high scalability, and seamless Laravel integration, it eliminates the need for third-party services while providing exceptional performance.
✔ Easy Setup – Install with a single Artisan command.
✔ Production-Ready – Optimize with Supervisor, Nginx, and scaling.
✔ Secure – Supports SSL and origin restrictions.
✔ Monitorable – Integrates with Laravel Pulse.
By leveraging Laravel Reverb, developers can build real-time chat apps, live notifications, collaborative tools, and more—all within the Laravel ecosystem.
🚀 Ready to supercharge your Laravel app with real-time features? Try Laravel Reverb today!
No comments yet. Be the first to comment!
Please log in to post a comment:
Continue with Google