I have a web application that needs to refresh some values often because the changes have to be available almost in real time. To do this, I run via ajax a refresh.php routine every 15 seconds, which returns the updated information. Time that increases if there is no user activity.
I thought of the possibility of creating a service-worker in the browser (since I use it for pwa too), and in it create a web-socket, and then only when there is an update on the server, create a socket for ip's of the users which are logged in (and saved in a db), just to tell the user's browser that there is an update, then the web-socket triggers the javascript routine that connects to the server and does the update.
I do not know if it would be possible to create the socket just to inform that there is an update, because in this case, I do not want to leave the socket open, creating the connection only when there is an update of the information, which in this case should happen for several users.
Has anyone ever needed or done anything like this, or would you have any other ideas?