imperium2335 Posted December 19, 2011 Share Posted December 19, 2011 Is there a way to use PHP sockets to simply detect when a user has disconnected from your server? e.g. When the user arrives on the website/app, a socket connection is made and a flag set in the database indicating they are online, when they leave the socket disconnects and the flag is reset. Quote Link to comment Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 Are you talking about just a normal website? That sounds like a very odd approach. Just do the normal and set a last_active flag for your SESSION. If it is, say, 10 minutes old without being updated then mark them as offline. Quote Link to comment Share on other sites More sharing options...
imperium2335 Posted December 19, 2011 Author Share Posted December 19, 2011 Its for an AJAX chat application. I am struggling to come up with a reliable way on how to detect if a user has disconnected due to say a power outage etc, and not to rely on 'onBeforeUnload' and other similar functions (javascript). Quote Link to comment Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 Simply put, it's not possible. Quote Link to comment Share on other sites More sharing options...
imperium2335 Posted December 19, 2011 Author Share Posted December 19, 2011 I thought of using exec to ping the users ip but not all users are pingable, is that statement true? If it really isn't possible, then an automatic timeout if the user does nothing for 30 minutes is the best method? What about HTML5 Sockets? Again though, not all browsers support HTML5 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 19, 2011 Share Posted December 19, 2011 Correct, not all users are pingable. ICMP replies and requests can be filtered off and discarded, and they frequently are. Quote Link to comment Share on other sites More sharing options...
scootstah Posted December 20, 2011 Share Posted December 20, 2011 I thought of using exec to ping the users ip but not all users are pingable, is that statement true? If it really isn't possible, then an automatic timeout if the user does nothing for 30 minutes is the best method? What about HTML5 Sockets? Again though, not all browsers support HTML5 There's lots of weird little hacky methods, but nothing that is reliable and therefore not using. The only way to do it is to use assume they are no longer on the website if the last_active flag is X minutes old. 30 minutes sounds kind of high, especially for an AJAX chat. Quote Link to comment Share on other sites More sharing options...
imperium2335 Posted December 20, 2011 Author Share Posted December 20, 2011 I was thinking after 5 or 10 minutes they are put on a BRB status, nothing would be more annoying than going for a piss and coming back to find yourself logged out, hence the 30 minutes. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.