1

Laravel echo server is working on development environment, but it's not working on production...

I open my webpage that should receive events broadcasted from laravel echo server. So, browser console is not showing any errors like can't connect to ws://domain.com/socket.io/etc. Nothing on the server side, I can't see any client connected...

L A R A V E L  E C H O  S E R V E R

version 1.4.2

Starting server...

✔  Running at 0.0.0.0 on port 6001
✔  Listening for http events...
✔  Listening for redis events...

Server ready!

I expect to see stuff like:

0|Socket-Connection  | [11:17:01 AM] - ********** authenticated for: private-user.1
0|Socket-Connection  | [11:17:01 AM] - ********** joined channel: private-user.1

And this is in my resources/assets/js/bootstrap.js:

import Echo from "laravel-echo"
window.io = require('socket.io-client');

if (typeof io !== 'undefined') {
  window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: window.location.hostname + ':6001',
    transports: ['websocket', 'polling', 'flashsocket']
  });
}

What could be happening?

2 Answers 2

3

It's working now! I don't know exactly what I did to make it to work, maybe something related to Laravel Queue or Redis was the issue...

Laravel echo server

Here is thelaravel-echo-server.json that works for me:

{
        "authHost": "http://11.222.333.44",
        "authEndpoint": "/broadcasting/auth",
        "clients": [],
        "database": "redis",
        "databaseConfig": {
                "redis": {
                        "host": "127.0.0.1",
                        "port": "6379"
                },
                "sqlite": {
                        "databasePath": "/database/laravel-echo-server.sqlite"
                }
        },
        "devMode": false,
        "host": null,
        "port": "6001",
        "protocol": "http",
        "socketio": {},
        "sslCertPath": "",
        "sslKeyPath": "",
        "sslCertChainPath": "",
        "sslPassphrase": "",
        "subscribers": {
                "http": true,
                "redis": true
        },
        "apiOriginAllow": {
                "allowCors": true,
                "allowOrigin": "*",
                "allowMethods": "GET, POST",
                "allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id"
        }
}

Note: http://11.222.333.44 is the website address.

Laravel Queue

Another thing that was wrong for sure: queue:work process was starting with the wrong queue connection (SQS) by Supervisor, as it is in the Laravel Docs:

command=php /home/forge/app.com/artisan queue:work sqs --sleep=3 --tries=3

I don't use Amazon SQS as queue connection, rather I use Redis by default (specified as QUEUE_DRIVER in .env), that's why it was generating this error:

[2018-10-03 09:19:50] prod.ERROR: Error executing "ReceiveMessage" on "https://sqs.us-east-1.amazonaws.com/your-account-id/your-queue-name"; AWS HTTP error: Client error: `POST https://sqs.us-east-1.amazonaws.com/your-account-id/your-queue-name` resulted in a `403 Forbidden` response:
<?xml version="1.0"?><ErrorResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/"><Error><Type>Sender</Type><Code>I (truncated...)
 InvalidClientTokenId (client): The security token included in the request is invalid. - <?xml version="1.0"?><ErrorResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/"><Error><Type>Sender</Type><Code>InvalidClientTokenId</Code><Message>The security token included in the request is invalid.</Message><Detail/></Error><RequestId>1ef4235d-f932-578c-9c34-77734f141e56</RequestId></ErrorResponse> {"exception":"[object] (Aws\\Sqs\\Exception\\SqsException(code: 0): Error executing \"ReceiveMessage\" on \"https://sqs.us-east-1.amazonaws.com/your-account-id/your-queue-name\"; AWS HTTP error: Client error: `POST https://sqs.us-east-1.amazonaws.com/your-account-id/your-queue-name` resulted in a `403 Forbidden` response:
<?xml version=\"1.0\"?><ErrorResponse xmlns=\"http://queue.amazonaws.com/doc/2012-11-05/\"><Error><Type>Sender</Type><Code>I (truncated...)
 InvalidClientTokenId (client): The security token included in the request is invalid. - <?xml version=\"1.0\"?><ErrorResponse xmlns=\"http://queue.amazonaws.com/doc/2012-11-05/\"><Error><Type>Sender</Type><Code>InvalidClientTokenId</Code><Message>The security token included in the request is invalid.</Message><Detail/></Error><RequestId>1ef4235d-f932-578c-9c34-77734f141e56</RequestId></ErrorResponse> at /var/www/html/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php:192, GuzzleHttp\\Exception\\ClientException(code: 403): Client error: `POST https://sqs.us-east-1.amazonaws.com/your-account-id/your-queue-name` resulted in a `403 Forbidden` response:
<?xml version=\"1.0\"?><ErrorResponse xmlns=\"http://queue.amazonaws.com/doc/2012-11-05/\"><Error><Type>Sender</Type><Code>I (truncated...)
 at /var/www/html/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113)
[stacktrace]
#0 /var/www/html/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php(101): Aws\\WrappedHttpHandler->parseError(Array, Object(GuzzleHttp\\Psr7\\Request), Object(Aws\\Command), Array)
#1 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(203): Aws\\WrappedHttpHandler->Aws\\{closure}(Array)
#2 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(174): GuzzleHttp\\Promise\\Promise::callHandler(2, Array, Array)
#3 /var/www/html/vendor/guzzlehttp/promises/src/RejectedPromise.php(40): GuzzleHttp\\Promise\\Promise::GuzzleHttp\\Promise\\{closure}(Array)
#4 /var/www/html/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\\Promise\\RejectedPromise::GuzzleHttp\\Promise\\{closure}()
#5 /var/www/html/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(96): GuzzleHttp\\Promise\\TaskQueue->run()
#6 /var/www/html/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(123): GuzzleHttp\\Handler\\CurlMultiHandler->tick()
#7 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(246): GuzzleHttp\\Handler\\CurlMultiHandler->execute(true)
#8 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(223): GuzzleHttp\\Promise\\Promise->invokeWaitFn()
#9 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(267): GuzzleHttp\\Promise\\Promise->waitIfPending()
#10 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(225): GuzzleHttp\\Promise\\Promise->invokeWaitList()
#11 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(267): GuzzleHttp\\Promise\\Promise->waitIfPending()
#12 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(225): GuzzleHttp\\Promise\\Promise->invokeWaitList()
#13 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\\Promise\\Promise->waitIfPending()
#14 /var/www/html/vendor/aws/aws-sdk-php/src/AwsClientTrait.php(59): GuzzleHttp\\Promise\\Promise->wait()
#15 /var/www/html/vendor/aws/aws-sdk-php/src/AwsClientTrait.php(78): Aws\\AwsClient->execute(Object(Aws\\Command))
#16 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/SqsQueue.php(120): Aws\\AwsClient->__call('receiveMessage', Array)
#17 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(244): Illuminate\\Queue\\SqsQueue->pop('https://sqs.us-...')
#18 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(105): Illuminate\\Queue\\Worker->getNextJob(Object(Illuminate\\Queue\\SqsQueue), 'your-queue-name')
#19 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(101): Illuminate\\Queue\\Worker->daemon('sqs', 'your-queue-name', Object(Illuminate\\Queue\\WorkerOptions))
#20 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(85): Illuminate\\Queue\\Console\\WorkCommand->runWorker('sqs', 'your-queue-name')
#21 [internal function]: Illuminate\\Queue\\Console\\WorkCommand->handle()
#22 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#23 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#24 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#25 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(549): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#26 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(180): Illuminate\\Container\\Container->call(Array)
#27 /var/www/html/vendor/symfony/console/Command/Command.php(252): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#28 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(167): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#29 /var/www/html/vendor/symfony/console/Application.php(936): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#30 /var/www/html/vendor/symfony/console/Application.php(240): Symfony\\Component\\Console\\Application->doRunCommand(Object(Illuminate\\Queue\\Console\\WorkCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#31 /var/www/html/vendor/symfony/console/Application.php(148): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#32 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Application.php(88): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#33 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#34 /var/www/html/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#35 {main}
"}

So I fixed it by removing sqs from command in my /etc/supervisor/conf.d/laravel-worker.conf, so it starts the queue using the default queue connection:

command=php /home/forge/app.com/artisan queue:work --sleep=3 --tries=3

And then restarting supervisor:

sudo supervisorctl reread

sudo supervisorctl update

sudo supervisorctl start laravel-worker:*

Redis

Also, I was trying to store Redis logfile, which for some uknown reason was generating errors when starting redis. So I just decided not to store logfile anymore by leaving logfile empty in Redis configuration (/etc/redis/redis.conf). PS.: I have installed and configured Redis for Ubuntu 16.04 as described here.

Sign up to request clarification or add additional context in comments.

Comments

0

if (typeof window.io !== 'undefined') {
  window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: window.location.hostname + ':6001',
    transports: ['websocket', 'polling', 'flashsocket']
  });

4 Comments

here io is not defined .so use windo.io
Hey @LDS welcome! Thanks, but it still not working on production. It was working on development with if (typeof io !== 'undefined') { (I will update the question with this information)
(typeof window.io !== 'undefined') {
Yes, I know. It was working even without window. on my local development environment, that's not the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.