Sorry, it is after 3:00am and I'm exhausted...
My website is heavy into content, and so I have lots of Articles about various topics. Registered Users are allowed to post Comments to each Article.
Each Comment looks very similar to our Posts here on SitePoint and includes the Comment, plus to the left the User's Username, Online Status, Photo, Location, and # of Posts.
If YOU just finished reading "Postage Meters Can Save You Money" and you were looking at other Users' Comments, then I need some way to show whether or not each "Commenter" is Online or Offline.
I can't determine that by looking at each Commenter's Session, so I have decided to store a piece of information on each Commenter in the "member" table in my database.
I haven't completely figured things out - obviously - but this is what I dreamed up last night...
When a User logs in I set logged_in = 1 and last_activity = now()
When a Reader finishes reading an Article and wants to see what others think, the System will display a listing of all Comments pertaining to that Article. For each Commenter, if now() - last_activity < 15 minutes then the Online Indicator is green. If now() - last_activity > 15 minutes but < 30 minutes then the Online Indicator is yellow. And if now() - last_activity > 30 minutes then the Online Indicator is grey and ideally "logged_in" will be reset to "0".
Each time a User does something (e.g. Logs In, Submits a Form, Navigates, etc.) last_activity to is updated to now().
If a User closes his/her browser without using the "Log Out" link, then I would have a logged_in = 1 in my database and no way to log out a User.
So I thought to myself last night, "For all places where the User needs to be logged in, I could check both logged_in and last_activity. If a User is logged_on but the last_activity is greater than 30 minutes, then I treat them as logged out in my scripts and I find a way to manually go in and update the User record so that logged_in = 0 again. (Thus the reason for this thread.)
Is this approach ideal? No! But I don't see a better way if I refuse to use Ajax which I am...
Hope that helps?!
How are you storing user/ visitor sessions?
I create a SESSION for each User when they log in.
As for the batch jobs, you can run PHP in cron jobs. Exactly how this works depends on your hosting. If you're using cPanel then there's an option to create cron jobs in there somewhere.
Guess I'll have to see what you think about what I said above before we discuss this?!