На ум приходит что то типа такого решения.
$mc = new Memcache;
$mc->connect('127.0.0.1', 11211);
$period = 30; // longpoll reconnect
$delay = 1; // reconnect delay
$uid = 1;
if(!$last_active = $mc->get("last_active_{$uid}")){
$mc->set("last_active_{$uid}", time());
die();
}
$now = time();
$online_time = $now - $last_active;
$counter = $mc->get("online_counter_{$uid}") ?: 0;
if($online_time < $period+$delay){
$counter += $online_time;
} else {
$counter += $period;
}
$mc->set("online_counter_{$uid}", $counter);
$mc->set("last_active_{$uid}", time());
echo "User ({$uid}) online time: {$counter}";