Current location: Hot Scripts Forums » Programming Languages » PHP » How to count online users


How to count online users

Reply
  #1 (permalink)  
Old 09-23-04, 04:07 AM
fox1999 fox1999 is offline
New Member
 
Join Date: Sep 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Question How to count online users

Hi to everybody,

i have an internet site (www.click4soccer.com) from some years and until now i have counted online users throught the use of database. But now i have the problem to relieve DB work because visitors is very high (we go up to 120 users online at the same time).

I'm looking to method to count visitors throught sessions as can i did with ASP (sesssion_start and session_end) but i don't know if with PHP is possible.

Somebody can help me to understand if and how i can monitor online users without use db?

Thanks
Reply With Quote
  #2 (permalink)  
Old 09-23-04, 04:37 AM
Masterhard Masterhard is offline
Newbie Coder
 
Join Date: May 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
IMHO database is the fastest way to work with large amounts of visitors. I think you should check if all needed table indexes are exist. Try to optimise your database.
__________________
Get free Bulletin Board and Hit Counter services at www.mh-sd.com
Reply With Quote
  #3 (permalink)  
Old 09-23-04, 04:55 AM
Bantam Bantam is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Reply With Quote
  #4 (permalink)  
Old 09-23-04, 06:13 AM
Eclipse's Avatar
Eclipse Eclipse is offline
Coding Addict
 
Join Date: May 2004
Location: Long Island, New York
Posts: 356
Thanks: 0
Thanked 0 Times in 0 Posts
I'm using a great one a wrote that simply sets a sessions then counts sessions here it is: {but keep in mind you must have already started the session}
PHP Code:

$count 0;

 
        
$handle4 opendir(session_save_path());
        if (
$handle4 == false) return -1;
 
        while ((
$file readdir($handle4)) != false) {
        if (
ereg("^sess"$file)) $count++;
        }
        
closedir($handle4); 
And the number of users online is set to $count. Hope that works for you.
Reply With Quote
  #5 (permalink)  
Old 09-23-04, 06:41 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Eclipse
I'm using a great one a wrote that simply sets a sessions then counts sessions here it is: {but keep in mind you must have already started the session}
PHP Code:

$count 0;

 
        
$handle4 opendir(session_save_path());
        if (
$handle4 == false) return -1;
 
        while ((
$file readdir($handle4)) != false) {
        if (
ereg("^sess"$file)) $count++;
        }
        
closedir($handle4); 
And the number of users online is set to $count. Hope that works for you.
just makes me wonder.. this counts all the session files in phps session dir right? but the session file is not deleted after sessions destroyd.. right now i have 5 session files on my local computer but i dont have any session running.. so makeing that work would require something to delete the session file when logout.. just a thought
Reply With Quote
  #6 (permalink)  
Old 09-23-04, 01:26 PM
Eclipse's Avatar
Eclipse Eclipse is offline
Coding Addict
 
Join Date: May 2004
Location: Long Island, New York
Posts: 356
Thanks: 0
Thanked 0 Times in 0 Posts
Are you running on a windows platform because on windows {in apache} you need to manuelally dealte sessions
Reply With Quote
  #7 (permalink)  
Old 09-23-04, 01:35 PM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Eclipse
Are you running on a windows platform because on windows {in apache} you need to manuelally dealte sessions
windows xp / apace 2
but i havent deleted any session files and opened probably 350 sessions..
this php.ini setting might have something to do with it:
Code:
; Define the probability that the 'garbage collection' process is started
; on every session initialization.
; The probability is calculated by using gc_probability/gc_divisor,
; e.g. 1/100 means there is a 1% chance that the GC process starts
; on each request.

session.gc_probability = 1
session.gc_divisor     = 100
Reply With Quote
  #8 (permalink)  
Old 09-23-04, 03:49 PM
Eclipse's Avatar
Eclipse Eclipse is offline
Coding Addict
 
Join Date: May 2004
Location: Long Island, New York
Posts: 356
Thanks: 0
Thanked 0 Times in 0 Posts
I know maybe it just doesn't work on the version that i have 4.3.1 also i set that to 1/1 so that could cause a silent error maybe...
Reply With Quote
  #9 (permalink)  
Old 05-22-06, 07:59 PM
---MTW--- ---MTW--- is offline
New Member
 
Join Date: Mar 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

What about to use an external provider for it? it seems to be better to use such a service if you have a high traffic web site.
Please check http://www.myonlineusers.com

Regards..

Quote:
Originally Posted by fox1999
Hi to everybody,

i have an internet site (www.click4soccer.com) from some years and until now i have counted online users throught the use of database. But now i have the problem to relieve DB work because visitors is very high (we go up to 120 users online at the same time).

I'm looking to method to count visitors throught sessions as can i did with ASP (sesssion_start and session_end) but i don't know if with PHP is possible.

Somebody can help me to understand if and how i can monitor online users without use db?

Thanks

Last edited by ---MTW---; 05-22-06 at 08:21 PM.
Reply With Quote
  #10 (permalink)  
Old 05-22-06, 09:36 PM
nova912's Avatar
nova912 nova912 is offline
Code Guru
 
Join Date: Sep 2004
Location: Traverse City, MI, USA
Posts: 821
Thanks: 0
Thanked 0 Times in 0 Posts
I belive it's your garbage collection... tha causing session to stick around. GC seems to be really flakey. You can, "i think", set session.gc.maxlifetime past 1440 (24 mins) to exstend the life that the session file has but be aware that the max life setting that is the lowest of any file in the session folder will be used and not the highest, and that is applied to all files in the session dir.

Hope that helps.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Flash to display users online... musiq The Lounge 2 08-15-04 01:59 AM
mirak.ca - Mirak Online Community System ykthinker General Advertisements 0 07-26-04 12:10 PM
Users Registration System postyourweb PHP 3 07-23-04 08:34 AM
Post count, why? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 7 10-06-03 03:29 PM
users online Stealth ASP 5 08-26-03 04:11 PM


All times are GMT -5. The time now is 04:31 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.