beyondcode / laravel-websockets

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

Realtime Statistics not showing #58

Closed kerrsmith closed 5 years ago

kerrsmith commented 5 years ago

I have followed the installation instructions step by step and have laravel-websockets working as expected - notifications are sent and received. I have also configured SSL support and this is also working. I am running the latest version of laravel-websockets 1.0.2.

When I view the Debug Dashboard I can see the Events at the bottom of the screen and these update in real time - I do not however see any statistics in the graph section at the top.

Do I need to do anything else to make this work? I can see the database table websockets_statistics_entries but it is empty, I tried sending lots of messages one after another but still do not get any data.

stayallive commented 5 years ago

Depending on you setup you need #31 in your life.

I had the same issue. Because my server is called via a hostname and not 127.0.0.1 the statistics request that is being made to the API never arrives.

kerrsmith commented 5 years ago

I have looked at the #31 link you suggested - thanks. My test server is a single Debian one with ISPConfig on it that I have used to set it up - it does not use load balanced or distributed services. It has 127.0.0.1 localhost set up in the hosts file and two nameservers listed in the resolv.conf file. It is a 'live' server that I use for testing, set up on a Digital Ocean droplet.

Basically it is a very simple webserver, directly connected to the internet.

Do I still need to update StartWebSocketServer.php and websockets.php to get it to work or it is a config change I need to make on the server?

Thanks for the help, I really appreciate it.

stayallive commented 5 years ago

Well #31 solves the issue in case your app is not available over 127.0.0.1, which in your case might be true, I don't know how ISPConfig configures vhosts but it could be listening on only your external IP and not on 127.0.0.1 (the current resolver of this package is hardcoded to always resolve 127.0.0.1 and never actually do a DNS lookup).

Also, the statistics collector makes a request to action([WebSocketStatisticsEntriesController::class, 'store']) for storing the numbers in the database and dispatching the event that should show up in your dashboard. In my case there are some things going on with some missing middleware (#28) and all routes being bound to a specific domain messing up the request url that the action generates.

I ended up needing to overwrite the service provider and add the ->domain() calls to the routes for the request to start working (and also apply #31).

kerrsmith commented 5 years ago

Thanks for the suggestions.

I have manually copied the latest src/Console/StartWebSocketServer.php file and added 'perform_dns_lookup' => true, to config/websockets.php and restarted artisan websockets:serve but I am still not seeing any graph data unfortunately.

I will check a few of the log files and see if I can see anything that shows any relevant information.

Thanks again for the help.

kerrsmith commented 5 years ago

I have now got it working. I looked in my apache access logs and saw lots of lines of:

/blog/laravel-websockets/statistics HTTP/1.0" 404

which was not correct, it did not need the blog part.

I found that I had added APP_URL=https://www.my-domain.com/blog to my .env when I first started this test site as I was testing a blog system and put that code in a directory called blog. It appears that the websockets code was using the blog part of APP_URL as its base for the path and adding the laravel-websockets/statistics part at the end.

As soon as I removed the blog part from the .env file (leaving just APP_URL=https://www.my-domain.com) and restarted artisan websockets:serve it started working.

Thanks again for the help with getting the code working.

stayallive commented 5 years ago

@kerrsmith ahhhh. Good one to check indeed 😄happy you got it working 👍

kerrsmith commented 5 years ago

Just as a final note - I have been testing the code again this morning since I found the apache errors last night. As a test I disabled the DNS lookup by setting 'perform_dns_lookup' to 'false' and the graph stops working.

Once I set 'perform_dns_lookup' to 'true' it starts working again so in my case I do need this new code added to make the statistics graph work.

khanhkid commented 5 years ago

@kerrsmith Thank you, I found same problem with you we need to change APP_URL=<websocket-domain> and keep perform_dns_lookup' => false Thank you for sharing

lorado commented 4 years ago

Thank you guys for the tips, I already spent a whole night trying to get statistic running.

Just for info: In my situation I had an extra problem - I defined basic auth via nginx to /laravel-websockets dashboard. But if you do so, statistic won't work. And you don't get any error, nowhere... It is better to use guard for dashboard, as described in the docs.

paleka commented 4 years ago

I see that this is an older thread but I I'll leave it for the next person. I had everything setup with SSL properly but the dashboard wasn't working. What fixed it was updating nginx configuration; remember to change http to https in proxy_pass https://127.0.0.1:6001;

d-damien commented 3 years ago

I had to let 'path' => 'laravel-websockets' − which defeats the purpose of this option, but it works (v1.11.1).