Jump to content

[SOLVED] How to make server auto' remove session files when expired ?!


shlomikalfa

Recommended Posts

hi there,

Q. How to make server auto' remove session files when expired ?!

 

current Session variables in PHP:

Session Support 	enabled
Registered save handlers 	files user sqlite
Registered serializer handlers 	php php_binary wddx

Directive	Local Value	Master Value
session.auto_start	Off	Off
session.bug_compat_42	On	On
session.bug_compat_warn	On	On
session.cache_expire	180	180
session.cache_limiter	nocache	nocache
session.cookie_domain	no value	no value
session.cookie_httponly	Off	Off
session.cookie_lifetime	0	0
session.cookie_path	/	/
session.cookie_secure	Off	Off
session.entropy_file	no value	no value
session.entropy_length	0	0
session.gc_divisor	100	100
session.gc_maxlifetime	1440	1440
session.gc_probability	1	1
session.hash_bits_per_character	4	4
session.hash_function	0	0
session.name	PHPSESSID	PHPSESSID
session.referer_check	no value	no value
session.save_handler	files	files
session.save_path	/tmp	/tmp
session.serialize_handler	php	php
session.use_cookies	On	On
session.use_only_cookies	Off	Off
session.use_trans_sid	0	0

 

As it seems to me, the session files should be deleted after 1440 seconds, but it doesn't happen... never!

any idea on how to make it work ?!

 

P.S> i need it done for the correct user statistics analysis...

oky, i've looked and found and read some posts about Garbage Collector and divisor and probabilities and soo.... but what i need to know now is:

 

Q. does ""session.gc_maxlifetime" starts it's count when there is no usage of the session file or is it fixed time limit for the file to exist on the server?

 

Q. is there any 'timer' that will allow these files to exists only as long as that cookie is being use with a usage time interval i am setting in advance ?

if anyone can please please please answer only these two questions it'll be of soo much help... please help!

 

Q. does ""session.gc_maxlifetime" starts it's count when there is no usage of the session file or is it fixed time limit for the file to exist on the server?

 

Q. is there any 'timer' that will allow these files to exists only as long as that cookie is being use with a usage time interval i am setting in advance ?

Yes i do want to use it to count online users !!!

if you have around 10K users online using MySQL slows the process and causes a lot of mess...

 

Anyhow, i've found this which seems to work.

-> it's just counts the files which have been accessed [fileatime()] in the last MAX_IDLE_TIME.

 

now i can set the GC to leave the files around for longer time periods and yet get the correct online-active-users count !

 

//Get the current active sessions count.
function getUsersOnline() {
   $count = 0;

   $handle = opendir(session_save_path());
   if ($handle == false) return -1;

   while (($file = readdir($handle)) != false) {
       if (ereg("^sess", $file)){
       		// Make sure this session has been accessed in the last MAX_IDLE_TIME time.
       		if(time()- fileatime(session_save_path() . '\\' . $file) < MAX_IDLE_TIME * 60){
			$count++;
		}
       }
   }
   closedir($handle);

   return $count;
}

 

[move]Thanks a lot for reading my post and help me !!![/move]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.