Skip to content

WebSockets (Reverb RT Broadcasting)

ColibriPlus uses Laravel Reverb to enable real-time features like chat, notifications, typing indicators, and more. To get WebSockets working correctly, you need to properly configure the Reverb server and make sure your environment is running on HTTPS with SSL.

🔴 Important: Laravel Reverb is automatically installed when you run composer install during the initial Installation Guide. You do not need to install it separately.

We just have to configure and set up with your HTTP server.

Below is a full explanation of each Reverb-related .env variable.

Configuration

  1. Open the .env file and edit the following variables:
bash
# Reverb server host that will be used to connect to the Reverb server.
# This is the host that will be used to connect to the Reverb server.
REVERB_SERVER_HOST=0.0.0.0

# Reverb server port that will be used to connect to the Reverb server.
REVERB_SERVER_PORT=13000

# Domain and port that will be used to connect to the reverb server from the client side.
# Add domain you are using for your application (e.g., myapp.com, localhost for development)
REVERB_HOST=your-domain.com
REVERB_PORT=443
REVERB_SCHEME=https

# Enable connection status monitoring
VITE_REVERB_CONNECTION_STATUS=on

💡 Development Setup: For local development, you can use REVERB_HOST=localhost and REVERB_PORT=13000 with REVERB_SCHEME=http

🔐 Reverb App Keys

Laravel Reverb uses a Pusher-compatible authentication system for broadcasting events, especially for private and presence channels. Even though you are not using Pusher.com, Laravel still requires these app-level keys to securely handle WebSocket communication.

These values must be defined in your .env file:

bash
REVERB_APP_ID=your-random-id
REVERB_APP_KEY=your-random-key
REVERB_APP_SECRET=your-random-secret

🔑 Security Note: Generate secure, random values for these keys.

Firewall Configuration

If you're running a firewall, make sure to allow traffic on your Reverb port:

bash
# For UFW (Ubuntu)
sudo ufw allow 13000

# For firewalld (CentOS/RHEL)
sudo firewall-cmd --permanent --add-port=13000/tcp
sudo firewall-cmd --reload

Start Reverb Server

If all configurations are done correctly, you can start the Reverb server by running the following command:

bash
# Rebuild the frontend before you start the Reverb server
npm run build

# Start the Reverb server
php colibri reverb:start

For development with detailed output:

bash
php colibri reverb:start --debug

Testing Your Setup

To verify your WebSocket connection is working properly:

  1. Start the Reverb server
  2. Open your browser's developer console on your application
  3. Look for successful WebSocket connection message (📶 Websockets connection is established.)
  4. Test real-time features like chat or notifications

You should see connection status indicators if VITE_REVERB_CONNECTION_STATUS=on is set.

Connection Limits

Each WebSocket connection is held in memory until either the client or server disconnects. In Unix and Unix-like environments, each connection is represented by a file. However, there are often limits on the number of allowed open files at both the operating system and application level.

On Linux, you can check the current limit with the following command:

bash
ulimit -n

If the limit is too low (typically less than 1024), you can increase it by editing the /etc/security/limits.conf file:

bash
sudo nano /etc/security/limits.conf

Add the following lines to the file:

bash
* soft nofile 10000
* hard nofile 10000

After making changes, log out and log back in, then restart the Reverb server:

bash
php colibri reverb:restart

Supervisor

For production environments, use Supervisor to manage the Reverb server. Supervisor is a process manager for Unix-like operating systems that can automatically restart the Reverb server if it crashes.

Create a Supervisor configuration file:

bash
sudo nano /etc/supervisor/conf.d/reverb.conf

Add the following configuration:

bash
[program:reverb]
# Replace with your actual path
directory=/path/to/your/colibriplus/
command=php colibri reverb:start
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/path/to/colibriplus/storage/logs/reverb.log
stopwaitsecs=3600

⚠️ Note: Set numprocs=1 for Reverb as it doesn't support multiple processes out of the box. For scaling, consider using a load balancer.

Apply the Supervisor configuration:

bash
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start reverb:*

Check the status:

bash
sudo supervisorctl status reverb:*

Troubleshooting

Common Issues

Connection Refused:

  • Verify the Reverb server is running
  • Check firewall settings
  • Ensure correct host/port configuration

SSL/TLS Errors:

  • Verify your SSL certificate is valid
  • Ensure your reverse proxy (Nginx/Apache) is properly configured for WebSocket upgrades

High Memory Usage:

  • Monitor connection counts
  • Implement connection limits in your application
  • Consider increasing server resources

Debug Mode

For detailed troubleshooting information:

bash
php colibri reverb:start --debug

Debug mode will show you:

  • Connection attempts
  • Authentication failures
  • Message broadcasting details
  • Memory usage statistics

Log Files

Check application logs for Reverb-related errors:

bash
tail -f storage/logs/laravel.log

If using Supervisor, check the Reverb-specific logs:

bash
tail -f storage/logs/reverb.log

Official Documentation

For more advanced configuration and features, refer to the official Laravel Reverb documentation.


📋 Quick Checklist:

  • .env variables configured
  • ✅ HTTPS/SSL properly set up
  • ✅ Firewall ports opened
  • ✅ Reverb server starts without errors
  • ✅ WebSocket connections working in browser
  • ✅ Supervisor configured (production)
  • ✅ Connection limits adjusted if needed

Developed by Mansur Terla. www.terla.me