I don't think you could be 100% accurate and get exact seconds unless you make some kind of ajax call on every page every second which would incrementally increase a value in the db for something like time_online, on the other hand if you were to round the ajax polling to like 45 seconds or a minute you could probably do something with it that wouldn't kill your db with constant writes for every online user every second.