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

ali2535's avatar

WebSocket is closed before the connection is established.

I am using pusher for laravel and I want to test results in the localhost. there is some problems with it and I get "WebSocket is closed before the connection is established" error. my configurations are :

.env

BROADCAST_DRIVER=pusher
PUSHER_APP_ID=local
PUSHER_APP_KEY=local
PUSHER_APP_SECRET=local

broadcasting.php

'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'),
				'encrypted' => false,
				'host' 		=> '127.0.0.1',
				'port'		=> 6001,
				'scheme' 	=> 'http'
            ],
        ],

bootstrap.js

import Echo from 'laravel-echo';

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'local',
    encrypted: false,
    wsHost: window.location.hostname,
    wsPort: 6001,
    // wssPort: 6001,
    disableStats: true,
    transports: ['websocket']
});

I have search this error a lot on the internet but i haven't gotton any answeres to solve problem yet

0 likes
4 replies
Sinnbeck's avatar

What are you using as server? Pusher? Laravel websockets (pusher replacement)?

Why have you set the host to 127.0.0.1?

kamr's avatar

@Sinnbeck what host should it be set then? I have same problem, please help with this

tinfoilman's avatar

I have no idea if this does anything, but in the bootstrap.js Echo instance of my working app I use enabledTransports: ['ws', 'wss'], where yours says transports: ['websocket'].

Please or to participate in this conversation.