Laravel Reverb: A Complete Guide to Real-Time WebSocket Communication in Laravel 12

Author

Kritim Yantra

Apr 05, 2025

Laravel Reverb: A Complete Guide to Real-Time WebSocket Communication in Laravel 12

Introduction

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.


What is Laravel Reverb?

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.

Key Features of Laravel Reverb

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.


Installing Laravel Reverb

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.


Configuration

1. Application Credentials

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

2. Allowed Origins

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).

3. Multiple Applications

Reverb can serve multiple applications from a single server:

'apps' => [
    ['app_id' => 'app-one'],
    ['app_id' => 'app-two'],
],

Running the Reverb Server

Start the server with:

php artisan reverb:start

Custom Host & Port

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

Debugging Mode

Enable debug logs with:

php artisan reverb:start --debug

SSL Configuration

For secure WebSocket connections (wss://), Reverb supports SSL via:

  • Laravel Herd / Valet (automatic SSL for local development)
  • Manual SSL certificates (config/reverb.php):
'options' => [
    'tls' => [
        'local_cert' => '/path/to/cert.pem',
    ],
],

Running Reverb in Production

1. Process Management (Supervisor)

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

2. Reverse Proxy (Nginx)

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;
}

3. Increase Open File Limits

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

4. Optimize Nginx for High Traffic

Update /etc/nginx/nginx.conf:

worker_rlimit_nofile 10000;
events {
    worker_connections 10000;
}

Scaling Reverb Horizontally

For high-traffic apps, run multiple Reverb servers behind a load balancer:

  1. Enable Scaling in .env:
    REVERB_SCALING_ENABLED=true
    
  2. Use a Central Redis Server (for pub/sub messaging).
  3. Deploy Multiple Reverb Instances behind a load balancer.

Monitoring with Laravel Pulse

Track connections & messages in real-time:

  1. Install Pulse:
    composer require laravel/pulse
    php artisan pulse:install
    
  2. Configure Pulse Recorders (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],
    ],
    
  3. Add Pulse Cards:
    <x-pulse>
        <livewire:reverb.connections cols="full" />
        <livewire:reverb.messages cols="full" />
    </x-pulse>
    

Conclusion

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.

Key Takeaways

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!

Tags

Laravel

Comments

No comments yet. Be the first to comment!

Please log in to post a comment:

Continue with Google

Related Posts