> ## Documentation Index
> Fetch the complete documentation index at: https://cloud.laravel.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Laravel Cloud WebSockets

> Fully managed WebSocket clusters

## Introduction

Laravel Cloud offers a fully managed WebSocket infrastructure powered by [Laravel Reverb](https://laravel.com/docs/reverb) clusters. Laravel Reverb is a Pusher-compatible WebSocket cluster which offers support for private channels, presence channels, client-events, and more, making it easy to add real-time features and functionality to your Laravel applications.

You can create Laravel Reverb powered WebSocket clusters directly from the Laravel Cloud dashboard (no external accounts needed) and attach them to your application's environments.

## Laravel Reverb

[Laravel Reverb](https://reverb.laravel.com/) is an open source, high-performance WebSocket cluster designed specifically for Laravel applications.

When running managed Laravel Reverb on Laravel Cloud, Reverb clusters are automatically provisioned and fully managed by Cloud, allowing you to avoid the time, complexity, and DevOps expertise typically required to set up and maintain a scalable and high-availability WebSocket cluster manually.

See the [pricing docs](/pricing#laravel-reverb) for details on concurrent connections, limitations, and pricing.

### Creating clusters

To create a Laravel Reverb powered WebSocket cluster, go to your Organization's "Resources" page, click the "WebSockets" tab, then click "+ New WebSocket cluster". Laravel Cloud will prompt you to select a region and the maximum number of concurrent connections your cluster needs to be able to handle.

Laravel Cloud will automatically create a default WebSocket application for you called `main`. To attach it to an environment, go to your application canvas and click "Add resource" -> "WebSockets".  WebSocket applications allow you to segment and share your cluster capacity across multiple applications and environments.

Once the WebSocket application has been attached to the environment, redeploy your application for the changes to take effect.

### Connecting your application

<Tabs>
  <Tab title="Laravel">
    Ensure your application has Laravel Reverb and Laravel Echo installed:

    ```sh theme={null}
    composer require laravel/reverb
    npm install --save-dev laravel-echo pusher-js
    ```

    Cloud automatically injects the Reverb environment variables needed by your application, including the frontend variables required by the [Laravel Echo](https://laravel.com/docs/12.x/broadcasting#client-side-installation) JavaScript client. No manual configuration is required.

    ```
    REVERB_APP_ID=10001
    REVERB_APP_KEY=********
    REVERB_APP_SECRET=********
    REVERB_HOST=ws-********-reverb.laravel.cloud
    REVERB_PORT=443
    REVERB_SCHEME=https
    REVERB_VERIFY_SSL=true

    VITE_APP_NAME="${APP_NAME}"

    VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
    VITE_REVERB_HOST="${REVERB_HOST}"
    VITE_REVERB_PORT="${REVERB_PORT}"
    VITE_REVERB_SCHEME="${REVERB_SCHEME}"
    ```
  </Tab>

  <Tab title="Symfony">
    Cloud's WebSocket clusters use the Pusher protocol, which is compatible with any Pusher-protocol client library. Ensure your application has the required packages installed:

    ```sh theme={null}
    composer require pusher/pusher-php-server
    npm install pusher-js
    ```

    Cloud automatically injects the Reverb environment variables when a WebSocket application is attached to your environment:

    ```
    REVERB_APP_ID=10001
    REVERB_APP_KEY=********
    REVERB_APP_SECRET=********
    REVERB_HOST=ws-********-reverb.laravel.cloud
    REVERB_PORT=443
    REVERB_SCHEME=https
    REVERB_VERIFY_SSL=true
    ```

    Register the Pusher client as a service in `config/services.yaml`, wiring the injected environment variables to the SDK:

    ```yaml theme={null}
    # config/services.yaml
    services:
        Pusher\Pusher:
            arguments:
                $auth_key: '%env(REVERB_APP_KEY)%'
                $secret: '%env(REVERB_APP_SECRET)%'
                $app_id: '%env(REVERB_APP_ID)%'
                $options:
                    host: '%env(REVERB_HOST)%'
                    port: '%env(int:REVERB_PORT)%'
                    scheme: '%env(REVERB_SCHEME)%'
                    useTLS: true
                    verify: '%env(bool:REVERB_VERIFY_SSL)%'
    ```

    You can then inject `Pusher\Pusher` into any service or controller via autowiring.

    `REVERB_APP_KEY` and `REVERB_HOST` are safe to expose to the browser (for example, rendered into your frontend templates for the JS client). `REVERB_APP_SECRET` is used for server-side authentication only and should never be exposed publicly.

    After your first deployment, add your application's Cloud domain to the WebSocket cluster's allowed origins. Without this step, browser connections will fail silently.

    1. Go to your organization's **Resources** page and navigate to the **WebSockets** tab.
    2. Click "..." on your cluster and select **Edit settings**.
    3. Add your application's Cloud domain to the allowed origins list.
  </Tab>
</Tabs>

### Editing, resizing, and splitting clusters

You can edit and resize your WebSocket cluster via your organization's "Resources" page. Go to "WebSocket clusters" and click the "..." icon on your cluster, then click "Edit settings".

You can use a single WebSocket cluster across multiple applications by splitting the maximum concurrent connections you have provisioned to your cluster across multiple WebSocket applications.

<Frame>
  <img src="https://mintcdn.com/cloud/thuCZ7zGzZwBXkQS/images/distribute_websockets_connections.png?fit=max&auto=format&n=thuCZ7zGzZwBXkQS&q=85&s=586c0ae511eb425ec0f5b12c9e5d0078" width="490" height="280" data-path="images/distribute_websockets_connections.png" />
</Frame>

You can choose an even distribution or manually configure a custom split.

### Metrics

You may view your WebSocket metrics, such as Connection Count and Message Rate, via your organization's "Resources" page. From the "Resources" page, navigate to the "WebSockets" tab and click the "..." icon for an active Reverb cluster. Then, click "View metrics".

Use the drop-down in the top right to drill down into the metrics of an individual application.

### Detaching applications

If a WebSocket cluster is no longer needed by your application, you can detach it from your application canvas.

<Frame>
  <img src="https://mintcdn.com/cloud/thuCZ7zGzZwBXkQS/images/detach_websockets.png?fit=max&auto=format&n=thuCZ7zGzZwBXkQS&q=85&s=a19462873c98472f7069ec2eee1f0e2f" width="574" height="282" data-path="images/detach_websockets.png" />
</Frame>

<Warning>
  Detaching a WebSocket application from an environment does not delete the cluster or stop it from accruing usage charges.
</Warning>

### Deleting clusters

You may delete a WebSocket cluster via your organization's "Resources" page. From the "Resources" page, navigate to the WebSockets tab and click the ”…” icon for the cluster you would like to delete. Then, click “Delete cluster”.

## Other WebSocket providers

If you don't want to use Laravel Reverb powered WebSocket clusters, you can pair Laravel Cloud with an external WebSocket provider like Pusher or Ably. Both are compatible with Laravel event broadcasting and Laravel Echo. You will, however, need to manage your WebSocket infrastructure and billing outside of Laravel Cloud and manage your environment variables manually.
