I agree with everything justsomeone said above, but with a slight modification. Point 4 you can combine with point 1 rather than using a cron. Perform that action whenever somebody visits a page.
But personally, I wouldn't do point 4 at all. Any timestamps that are older than (n) minutes can simply be assumed to be inactive. There's really no need to remove them, is there?