Either way works just as well, as I think. I just have a personal preference to collection information and act on it seperately, rather than do logic at the collection level. There's really only two SQL statements to do something like this:
To log a timestamp for a particular game/product (could also set a variable like $now = time() in PHP, instead of using SQL functions):
Code:
INSERT INTO active_players (
game_id
,timestamp
)
VALUES (
1
,unix_timestamp()
)
To get the current number of players (900 seconds needs to match the client reporting frequency):
Code:
SELECT count(*) as countActivePlayers
FROM active_players
WHERE game_id = 1
AND timestamp > unix_timestamp() - 900
I see the benefits as being more accurate statistics (still a ping window to deal with, but can generate the active count anytime), and the ability to add more functionality on top (could log a unique machine hash or identifier to detect player session length and get stats on repeat visitors).