Is there a simple and efficient way to get the number of visitors who have a given web page open?
The ultimate goal is to do this:
n
, display a button. The first x
visitors who press the button would go to a different page.n
visitors, the button will keep displaying. If not, the button disappears.Any trick for doing this? Long-polling? Websocket? The simpler the better.
Well you could either use Websocket's like you have mentioned or just simple AJAX to poll the server every 100ms, and until the Websocket hasn't been closed or until the server didn't get a response from the browser for 500ms then the user is "connected" using AJAX.
And just add all those users which are connected to a page to a database based on their page and distinct ip's on a page, and count them once there are n
entries on a specific page return a response to all browsers to show the button.
And if there are less than n
just send a response to hide the button.