imperium2335 Posted July 31, 2011 Share Posted July 31, 2011 Hi, I am building a simple AJAX chat system, but I have thought of an issue. What if a user pulls the plug on the connection for whatever reason (powercut etc), how will my system know to remove their "active users" entry in my DB and thus show them as no longer in the chat? Is there a way to check for a client of a given IP address taking part in an AJAX request? So I could have something where if no AJAX request was made in 10 seconds, they must have disconnected? Any help or advice is much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/243381-is-client-still-there/ Share on other sites More sharing options...
ignace Posted July 31, 2011 Share Posted July 31, 2011 Just ask them All jokes aside! Yes, you would poll your server every n seconds to fetch the new contents and update their status, anyone where the delta between last update time and the current time exceeds the idle time is considered offline. Preferably you should return this to any active clients so they can update their list of users in the chat. Quote Link to comment https://forums.phpfreaks.com/topic/243381-is-client-still-there/#findComment-1249801 Share on other sites More sharing options...
imperium2335 Posted July 31, 2011 Author Share Posted July 31, 2011 Thanks for the reply! Yes I already have something that deletes a user if no activity after 30 minutes, but I want to know if there is a way to detect if they have hard disconnected. I thought about pinging the clients IP address using phps exec() function but I hear not everyone on the net is pingable. What do you think? Quote Link to comment https://forums.phpfreaks.com/topic/243381-is-client-still-there/#findComment-1249804 Share on other sites More sharing options...
ignace Posted July 31, 2011 Share Posted July 31, 2011 Pinging won't solve anything. Pinging only means that the host is reachable not that they are still chatting. So no, there is no real way except maybe using the onunload event of which I'm unsure if it triggers correctly on all browsers/platforms. What you actually need is a socket which is available as of HTML5: WebSockets, you can find a tutorial of how to use it on NetTuts+ Quote Link to comment https://forums.phpfreaks.com/topic/243381-is-client-still-there/#findComment-1249846 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.