Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

armancs's avatar

Laravel 11 websocket connection error

[Error] WebSocket connection to 'wss://askandanswers.com:8080/app/5itakxzndee1dovsy6w7?protocol=7&client=js&version=8.4.0-rc2&flash=false' failed: WebSocket is closed before the connection is established. close (app-m_5yzilV.js:28:19349) abort (app-m_5yzilV.js:29:7469) (anonymous function) (app-m_5yzilV.js:28:39519) (anonymous function) (app-m_5yzilV.js:28:11389) (anonymous function) (app-m_5yzilV.js:28:11099)

Tried different way: REVERB_HOST="localhost" REVERB_PORT=8080 REVERB_SCHEME=http

REVERB_HOST="localhost" REVERB_PORT=8080 REVERB_SCHEME=https

REVERB_HOST=domainname.com REVERB_PORT=8080 REVERB_SCHEME=https

REVERB_HOST=domainname.com REVERB_PORT=8080 REVERB_SCHEME=http

but still the same error:

Please help me to get rid of this. TIA

0 likes
5 replies
vincent15000's avatar

For me it works fine.

Here is my configuration.

// .env

REVERB_HOST=localhost
REVERB_PORT=8080
REVERB_SCHEME=http

VITE_REVERB_APP_KEY=${REVERB_APP_KEY}
VITE_REVERB_HOST=${REVERB_HOST}
VITE_REVERB_PORT=${REVERB_PORT}
VITE_REVERB_SCHEME=${REVERB_SCHEME}

// bootstrap.js

import Echo from 'laravel-echo';

import Pusher from 'pusher-js';
window.Pusher = Pusher;

window.Echo = new Echo({
    broadcaster: 'reverb',
    key: import.meta.env.VITE_REVERB_APP_KEY,
    wsHost: import.meta.env.VITE_REVERB_HOST,
    wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,
    wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
    forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https',
    enabledTransports: ['ws', 'wss'],
});

// a view with AlpineJS

x-data="{
    loggedInUserIds: [],
}"
x-init="
    Echo.join('speed-dating')
        .here((users) => {
            loggedInUserIds = users.map((user) => user.id);
        })
        .joining((user) => {
            loggedInUserIds.push(user.id);
        })
        .leaving((user) => {
            loggedInUserIds.splice(loggedInUserIds.indexOf(user.id), 1);
        })
        .error((error) => {
            console.error(error);
        });
"
armancs's avatar

@vincent15000 Sorry I forgot to mention that I tried to deploy in production (VPS Server). In my localhost, everything works fine.

This is my bootstrap.js:

import Echo from 'laravel-echo';
import Pusher from 'pusher-js';

window.Pusher = Pusher;

window.Echo = new Echo({
    broadcaster: 'reverb',
    key: import.meta.env.VITE_REVERB_APP_KEY,
    wsHost: import.meta.env.VITE_REVERB_HOST,
    wssHost: import.meta.env.VITE_REVERB_HOST ?? 'localhost',
    wsPort: import.meta.env.VITE_REVERB_PORT ?? 8080,
    wssPort: import.meta.env.VITE_REVERB_PORT ?? 8080,
    forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https',
    enabledTransports: ['ws', 'wss'],
});
1 like
armancs's avatar

vps now fixed with htpp issues. but now getting this error in consoel:

[Error] WebSocket connection to 'wss://askandanswers.com:8080/app/5itakxzndee1dovsy6w7?protocol=7&client=js&version=8.4.0-rc2&flash=false' failed: WebSocket is closed before the connection is established.
	close (app-m_5yzilV.js:28:19349)
	abort (app-m_5yzilV.js:29:7469)
	(anonymous function) (app-m_5yzilV.js:28:39519)
	(anonymous function) (app-m_5yzilV.js:28:11389)
	(anonymous function) (app-m_5yzilV.js:28:11099)
[Error] WebSocket connection to 'wss://askandanswers.com:8080/app/5itakxzndee1dovsy6w7?protocol=7&client=js&version=8.4.0-rc2&flash=false' failed: WebSocket is closed due to suspension.```

Please or to participate in this conversation.