Question

In my local machine broadcasting and it works fine but in Production which is Digital ocean app platform it cannot connect to the server.

.env

BROADCAST_DRIVER=reverb

REVERB_APP_ID=my-app-id
REVERB_APP_KEY=my-app-key
REVERB_APP_SECRET=my-app-secret
REVERB_HOST=0.0.0.0        # Bind to all interfaces
REVERB_SCHEME=https         # Use https for security, especially since your app is hosted publicly
REVERB_PORT=6001            # Default port for WebSocket connections 

broadcasting.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Broadcaster
    |--------------------------------------------------------------------------
    |
    | This option controls the default broadcaster that will be used by the
    | framework when an event needs to be broadcast. You may set this to
    | any of the connections defined in the "connections" array below.
    |
    | Supported: "pusher", "ably", "redis", "log", "null"
    |
    */

    'default' => env('BROADCAST_DRIVER', 'reverb'),

    /*
    |--------------------------------------------------------------------------
    | Broadcast Connections
    |--------------------------------------------------------------------------
    |
    | Here you may define all of the broadcast connections that will be used
    | to broadcast events to other systems or over websockets. Samples of
    | each available type of connection are provided inside this array.
    |
    */

    'connections' => [

        'reverb' => [
            'driver' => 'pusher',  // Reverb mimics Pusher
            'key' => env('REVERB_APP_KEY', 'some-random-key'),
            'secret' => env('REVERB_APP_SECRET', 'some-random-secret'),
            'app_id' => env('REVERB_APP_ID', 'some-app-id'),
            'options' => [
                'host' => env('REVERB_HOST', 'mydigitaloceanlink'),  // Your actual domain
                'port' => env('REVERB_PORT', 443),  // Port for WSS
                'scheme' => env('REVERB_SCHEME', 'https'),  // Secure WebSocket
                'useTLS' => env('REVERB_SCHEME', 'https') === 'https',  // Match TLS to scheme
                'encrypted' => true,  // Ensure connection encryption
            ],
        ],

        'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'cluster' => env('PUSHER_APP_CLUSTER'),
                'useTLS' => env('REVERB_SCHEME') === 'https',
            ],
        ],

        'ably' => [
            'driver' => 'ably',
            'key' => env('ABLY_KEY'),
        ],

        'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
        ],

        'log' => [
            'driver' => 'log',
        ],

        'null' => [
            'driver' => 'null',
        ],

    ],

];

reverb.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Reverb Server
    |--------------------------------------------------------------------------
    |
    | This option controls the default server used by Reverb to handle
    | incoming messages as well as broadcasting message to all your
    | connected clients. At this time only "reverb" is supported.
    |
    */

    'default' => env('REVERB_SERVER', 'reverb'),

    /*
    |--------------------------------------------------------------------------
    | Reverb Servers
    |--------------------------------------------------------------------------
    |
    | Here you may define details for each of the supported Reverb servers.
    | Each server has its own configuration options that are defined in
    | the array below. You should ensure all the options are present.
    |
    */

    'servers' => [

        'reverb' => [
            'host' => env('REVERB_HOST', '0.0.0.0'),
            'port' => env('REVERB_PORT', 9000),
            'hostname' => env('REVERB_HOST'),
            'options' => [
                'tls' => [],
            ],
            'max_request_size' => env('REVERB_MAX_REQUEST_SIZE', 10_000),
            'scaling' => [
                'enabled' => env('REVERB_SCALING_ENABLED', false),
                'channel' => env('REVERB_SCALING_CHANNEL', 'reverb'),
                'server' => [
                    'url' => env('REDIS_URL'),
                    'host' => env('REDIS_HOST', '127.0.0.1'),
                    'port' => env('REDIS_PORT', '6379'),
                    'username' => env('REDIS_USERNAME'),
                    'password' => env('REDIS_PASSWORD'),
                    'database' => env('REDIS_DB', '0'),
                ],
            ],
            'pulse_ingest_interval' => env('REVERB_PULSE_INGEST_INTERVAL', 15),
            'telescope_ingest_interval' => env('REVERB_TELESCOPE_INGEST_INTERVAL', 15),
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Reverb Applications
    |--------------------------------------------------------------------------
    |
    | Here you may define how Reverb applications are managed. If you choose
    | to use the "config" provider, you may define an array of apps which
    | your server will support, including their connection credentials.
    |
    */

    'apps' => [

        'provider' => 'config',

        'apps' => [
            [
                'key' => env('REVERB_APP_KEY'),
                'secret' => env('REVERB_APP_SECRET'),
                'app_id' => env('REVERB_APP_ID'),
                'options' => [
                    'host' => env('REVERB_HOST'),
                    'port' => env('REVERB_PORT', 443),
                    'scheme' => env('REVERB_SCHEME', 'https'),
                    'useTLS' => env('REVERB_SCHEME') === 'https',  // Enable TLS for HTTPS
                ],
                'allowed_origins' => ['*'],
                'ping_interval' => env('REVERB_APP_PING_INTERVAL', 60),
                'activity_timeout' => env('REVERB_APP_ACTIVITY_TIMEOUT', 30),
                'max_message_size' => env('REVERB_APP_MAX_MESSAGE_SIZE', 10_000),
            ],
        ],

    ],

];

in my controller i try to broadcast this

                       broadcast(new FileUploaded($user->id, $file->getClientOriginalName(), $counter, $asset->id));
                   } catch (\Exception $e) {
                       // Log detailed error information
                       Log::error('Error broadcasting FileUploaded event:', [
                           'message' => $e->getMessage(),
                           'file' => $e->getFile(),
                           'line' => $e->getLine(),
                           'trace' => $e->getTraceAsString(),
                       ]);
                   } 

i got following error:

Local. ERROR: Error broadcasting FileUploaded event: ("message": "Pusher error: CURL error 7: Failed to connect to 0.0.0.0 port 6001 after 6 ms: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://0.0.0.0/apps/my-app-id/events?auth_key=my-app-key&auth_timestamp=1727691940&auth_version=1.0&body_md5=bdfd3fdcc3c19ab647114c8d4ca230e2&auth_signature=cd729c19fa4d846b99f424b7a856584445272f695ffe9ff26cc786@fe0e39a71.", "file": "/workspace/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php", "line": 164, "trace": "#0 /workspace/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastEvent.php(92): Illuminate\Broadcasting\Broadcasters\PusherBroadcaster->broadcast()")

Same thing happens with port 443 and port 8080 i got ssl error which is understandable. In console when i run start the server it is starting.

php artisan reverb:start --debug

   INFO  Starting server on 0.0.0.1:6001.  

  Pruning Stale Connections .......................................................................................  
  Pinging Inactive Connections 

From postman i tried wss connection but it is tied out. I am out of options now.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
November 24, 2024

Hey!

The DigitalOcean App Platform does not allow arbitrary ports like 6001 to be publicly accessible. You will need to expose specific routes for services.

For example, you can map your WebSocket server to a route like /apps that proxies requests to your broadcasting service running on a specific port (e.g., 6001).

Then rather than setting your Reverb host to 0.0.0.0:6001 you will need to set it to <https://your_domain/apps> instead so that the Laravel frontend will connect to that to that endpoint which is exposed publcily…

Basically:

  • Set the reverb server details to:
REVERB_SERVER_HOST=0.0.0.0
REVERB_SERVER_PORT=6001
  • Then for the Laravel web component set the Reverb host details to:
REVERB_HOST=your-domain.com
REVERB_PORT=443

Let me know if your project is open source, I will be happy to try and deploy it on my end to test this all out!

- Bobby

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.