I am developing a networking site with users and profiles and want to be able to show when a specific user is online.
At the moment when a user logs in I log the timestamp in the users table which I do use currently through the site to determine ‘recent active’ status in a loose kind of way. I’d still want to keep that but ideally be able to replace it during a user’s session with somekind of green light online now indicator.
Trawling Google for a little while I’ve come to the conclusion that using AJAX to ping the server every 5 minutes or so during a users session, to a script that uses REPLACE INTO
to insert/update records in a users_online
table then on a persons file I could just call a PHP function to check whether an the user has an entry in that table.
The jQuery/AJAX I’m looking to use is;
var stillAlive = setInterval(function () {
$.get("includes/process.php?do=online-ping&uid=<?php $_GET['uid']; ?>");
}, 50000);
Am I on the right path? Is there a better solution do you think?