What would your solution for real time UI updates be?
Right now I have a table that displays data about rapidly changing events once they're created.
So a user can create an event now, and it should be finished in up to 20 seconds from the moment of creation.
In those 20 seconds there are a few stages it goes through, but I just call all of them In progress in the status column of the table
Currently the way the table is updated to make it look like "real time" is using JavaScript with setTimeout of 5 seconds, and using ajax to check the db (every 5 seconds)
Are there issues with this approach? What would you do?
At first I suggested using web sockets but was told it's a bad idea since there are many users and opening many sockets right now is expensive or just not a good idea in general to have many web sockets opened? (But it could be due to cost issues, not sure? what do you think?)
@cooperino Well you need to decide how “important” realtime updating is for your application.
If you want realtime updates then yes, you’re going to need to use a web sockets approach where some server-side process emits events to your front-end as and when they occur.
If you stick to polling, then it won’t be realtime but you’ll be putting load on your server with HTTP requests regardless if there’s an update in status or not.
@Sinnbeck Are there downsides for using sockets over polling? I'm not sure why I was told sockets could cause issues, if polling is always sending HTTP requests and sockets only open when needed.
what did they mean when they said having many sockets is bad? Isn't it's something that takes a very short amount of time then it closes therefore it should be better than polling via ajax?
@cooperino hard to know without talking to them or reading the exact quote. But it could be due to the cost. Using a service like pusher can get very expensive very fast.
@Sinnbeck I installed an Ubuntu server on a VirtualBox VM and now SSH'ing to it from Windows using VSCode SSH extension. (moved the entire Laravel project from Windows to the Ubuntu VM)
Do I have to do it this way if I want to keep working from Windows, or there's a way to have the project code on Windows and only the queue worker on the VM?
@Sinnbeck Oh so your Laravel code is inside a Docker container and the soketi is on another container, and all run on Windows? (I had that setup before for local development, minus the soketi server)
You then SSH to the docker container from Windows?
@cooperino I actually run on linux mint as i dont like windows :) But the docker container just links the content from my machine and into the docker container, so its the same. I of course use lando to run commands inside the docker container, but all my regular development is on my host machine :)
And yes I have a container for each service. So one for php, one for nginx, one for mysql and one for soketi
You can do the same with laravel sail. I just prefer Lando as its easy to set up, and add tools to. It is also easy to set up a proxy to connect to something like soketi from both the browser, and inside laravel. And it comes with a https certificate out of the box :)
@Sinnbeck Oh nice and in your docker config there's a way to copy only the changed file over to the container? (I used docker quite a long time so forgot if that's possible)
So if your code is on the host, you have to build it to the container right? Is it configured in a way where every time you save a file locally on Mint, it "uploads" it to the container?
@cooperino Docker uses volumes to map between the container and your host system. So everytime you save a file it is automatically changed in the container and vice versa. It is just like a symlink on you computer :)
Lando handles the setup of all of this automatically