beyondcode / laravel-websockets

Websockets for Laravel. Done right.
https://beyondco.de/docs/laravel-websockets
MIT License
5.08k stars 628 forks source link

Stuck on "Starting the WebSocket server on port 6001" (Docker + Laravel Sail) #855

Closed Corinthian72 closed 3 years ago

Corinthian72 commented 3 years ago

In my local environment I'm using Laravel Sail and Docker Desktop.

Installed laravel-websockets in accordance with official docs

Also found issue #693 and forwarded the websockets port in my docker-compose.yml

version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/7.4
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-7.4/app
        ports:
            - '${APP_PORT:-80}:80'
            - '${LARAVEL_WEBSOCKETS_PORT:-6001}:${LARAVEL_WEBSOCKETS_PORT:-6001}'
        environment:
...

My configs

config/websockets.php

'apps' => [
    [
        'id' => env('PUSHER_APP_ID'),
        'name' => env('APP_NAME'),
        'key' => env('PUSHER_APP_KEY'),
        'secret' => env('PUSHER_APP_SECRET'),
        //'path' => env('PUSHER_APP_PATH'),
        'capacity' => null,
        'enable_client_messages' => false,
        'enable_statistics' => true,
    ],
],

config/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'),
        // 'useTLS' => true,
        'encrypted' => env('PUSHER_APP_ENCRYPTED'),
        'host' => env('PUSHER_APP_HOST'),
        'port' => env('PUSHER_APP_PORT'),
        'scheme' => env('PUSHER_APP_SCHEME')
    ],
],

.env

BROADCAST_DRIVER=pusher
...
PUSHER_APP_ID=Chat
PUSHER_APP_KEY=n2Cf8ExaYMKWZ3kN
PUSHER_APP_SECRET=peqSZA829GQaaQZn
PUSHER_APP_CLUSTER=mt1

PUSHER_APP_ENCRYPTED=false
PUSHER_APP_HOST=127.0.0.1
PUSHER_APP_PORT=6001
PUSHER_APP_SCHEME=http

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

When using "sail artisan websockets:serve" I always get stuck on "Starting the WebSocket server on port 6001"

When I use "php artisan websockets:serve" there are 2 outcomes

  1. Without port forwarding in docker-compose.yml - stuck on "Starting the WebSocket server on port 6001"

  2. With port forwarding in docker-compose.yml
    RuntimeException Failed to listen on "tcp://0.0.0.0:6001": Address already in use at vendor/react/socket/src/TcpServer.php:172

glupeksha commented 3 years ago

I have the same issue.

Corinthian72 commented 3 years ago

I have the same issue.

Somehow It works if i'm not trying to "websockets:serve" manualy, but starting websockets in supervisord.conf

[program:websockets]
command=/usr/bin/php /var/www/html/artisan websockets:serve
numprocs=1
autostart=true
autorestart=true
user=sail

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

config/websockets.php

'apps' => [
    [
        'id' => env('PUSHER_APP_ID'),
        'name' => env('APP_NAME'),
        'key' => env('PUSHER_APP_KEY'),
        'secret' => env('PUSHER_APP_SECRET'),
        'capacity' => null,
        'enable_client_messages' => false,
        'enable_statistics' => true,
    ],
],
crossRT commented 3 years ago

It's actually not stuck, it's just waiting for a new connection. I tot I was stuck at the beginning due to the message.