Jump to content

[SOLVED] Making session files stick forever.... never deleted!!!


shlomikalfa

Recommended Posts

how do i make them stick?!

it's like they are auto-deleted all the time and my users are set logged-out!

 

i want to use an own made function to delete session files based on "filemtime()" function... is that a good idea ?!

 

This is the function i have now, it should check if the user haven't modified his session file in the last hour and if so deletes it....

P.S my users are modifying their session file on every page change.

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()- filemtime(session_save_path() . '/' . $file) < MAX_IDLE_TIME * 60){
			$count++;
		}else{
			@unlink(session_save_path() . '/' . $file);
		}
       }
   }
   closedir($handle);

   return $count;
}

well... it seems like it's being cleared after 1 hour or maybe 2 hours....

 

i tried:

ini_set("session.gc_maxlifetime", "518400");

 

which seems like it doesn't work.....

P.S my sessions are in a folder inside my root-dir.... and not in main folder...

ohhh can't modify post...

 

-> can anyone please explain me exactly what does "session.gc_maxlifetime" means ?!

-> Does this ""Garbage collector" delete only files that haven't been modified in the last "session.gc_maxlifetime" time ?! or does it delete any file that exists more then "session.gc_maxlifetime" time ?!

 

-> Will setting my "session.gc_maxlifetime" to 72 hours but yet having my function:

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()- filemtime(session_save_path() . '/' . $file) < MAX_IDLE_TIME * 60){
            $count++;
         }else{
            @unlink(session_save_path() . '/' . $file);
         }
       }
   }
   closedir($handle);

   return $count;
}

 

have the effect of deleting files only if their not modified for over a desirable time ?!

-> can anyone please explain me exactly what does "session.gc_maxlifetime" means ?!

It's time (in seconds) after which garbage collector can throw sessions away

 

-> Does this ""Garbage collector" delete only files that haven't been modified in the last "session.gc_maxlifetime" time ?! or does it delete any file that exists more then "session.gc_maxlifetime" time ?!

None of the two. The right answer should be "only files that haven't been opened in the last 'session.gc_maxlifetime' time". On Linux systems, at least. For Win, the first of yours should fit.

 

-> Will setting my "session.gc_maxlifetime" to 72 hours but yet having my function:

.............

have the effect of deleting files only if their not modified for over a desirable time ?!

The main point is that if your sessions are in a shared directory, raising up 'session.gc_maxlifetime' will have no effect at all.

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.