I'm developing a iOS application and i'd like to check if a specific user is online or not. My first idea was to send cyclically at a distance of five seconds asynchronous connections from the application to a php page that updates a field in the database by inserting the current date and time. Then, to see if a particular user is online, the application fetch this data from the database every 5 seconds and compare it with the current time: if current time is greater than data collected (greater than 5 seconds), it means that the user is offline , otherwise it is online. This works but surely the instant messaging applications do not use this method because it is too expensive. Which approach should be used?
I hope i explained myself, thank you!
Here's how I would attack the problem:
I can see where you are going with time stamps, however with multiple users around the world with multiple connections, you would have to be lenient with your date & time entries and checks (however you seem to already have that in mind) because it takes longer times for some users' internet than others to respond.
EDIT: just saw your lat bit about instant messaging. From my experience if you are on a mobile device it isn't always instant (it seems to me that when I open up a chat conversation to someone on my phone over Facebook, their online status is not updated until I send the message/every set amount of time). Sometimes I will receive messages 30 seconds to a minute later on my phone after it has reached my computer. But this seems to be prioritised (ie: if I'm having a big conversation with someone with lots of messages going back and forth, communication is very instant)-just thought I'd share.