LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-07-2006, 01:21 AM   #1
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Rep: Reputation: 61
Users Online - PHP


Hi there, I'm currently building a custom forum for a client. They have asked me to have a section to see who is currently online. I was just curious what is the best way to go about this? Is there a way to simply read all of the $_SESSION['user_id'] sessions that are currently being stored?

Will appreciate anyone who can shed some light on this subject. If it matters at all, there server is a windows box, running php4 and mysql4. I control it all with Plesk.

Thanks.
 
Old 12-07-2006, 01:39 AM   #2
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
One approach is to use MySQL table for session management.

You can store each session in a sessions table in your forum MySQL database and clear out the "expired" sessions after a given duration to keep up to date. You can define "expiry" of a session in the database based on the cookie status or a time duration.

For this approach though, you would have to do more than merely using the default PHP session handling (as in just calling "session_start()" for every page). You might have to write a session handler which incorporates the approach I mentioned.

(you should probably run the "expiring" script in a cron job or whenever a page is reloaded. consider the costs/benefit of either approach).

Last edited by vharishankar; 12-07-2006 at 01:40 AM.
 
Old 12-07-2006, 01:53 AM   #3
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Original Poster
Rep: Reputation: 61
So... basically I create a table called... Users_online or something.

Store in there something like:
User_id
signin_time
last_activity_time

And then just update that everytime they cruise around the pages? And then set up a schedule script that runs every 25 minutes or something? Oh I suppose I could also kill the users record in the table if they choose to sign out.
 
Old 12-07-2006, 05:50 AM   #4
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
Yeah that's about it. I would also store the (encrypted) session Id and the IP address (useful for tracking guests as well as logged in users). Also you needn't use a scheduler using cron if you can run this script when a page is loaded or refreshed. But that would mean more load on the server every time a request is made.


A cron (or scheduler) job seems a better idea, but since it would not be part of the forum software itself, it might be dependent on the OS to run that scheduler.

Last edited by vharishankar; 12-07-2006 at 05:52 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding users with PHP (pass php variables to Expect script) Jayla Programming 1 10-20-2006 10:44 AM
squid - online users..? raj_deep2k1 Linux - Networking 1 01-22-2006 09:54 PM
Most users online mdg LQ Suggestions & Feedback 2 07-16-2005 09:57 AM
FC2 users in Sydney online right now? sausagejohnson Fedora 10 05-23-2004 07:28 PM
users online Mara LQ Suggestions & Feedback 4 01-21-2003 03:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration