Welcome Guest, Not a member yet? Register   Sign In
Question about deleting expired session files.
#1

I'm using latest stable version 3.x of CI with file system as session driver & sess_regenerate_destroy as false, and need help to understand why aren't old sessions files deleted.

As from CI documentation, I understood that the Garbage Collector should delete the expired session file automatically.

I can see that there are more than 800 session data files exist in folder specified by sess_save_path since last 2 months while my site has only 10 users and I was expecting files only to be a few and rest should be deleted automatically by Garbage Collector with time.

Can anyone help me to understand why are those files there and if I need to delete them by some script then what it should be?
Reply
#2

The GC does delete them automatically, but that doesn't happen immediately.

PHP has a gc_probability, gc_divisor session INI settings which form a "chance" value for the garbage collector to run during a request. Then, when it runs, it would delete sessions that haven't been used for more time than what is configured as gc_maxlifetime.

It's a bit confusing a first, but this is necessary for performance reasons, don't worry about it - old sessions will be deleted after some time, just as long as you don't have a gc_probability of 0.
Reply
#3

(09-02-2015, 01:46 AM)Narf Wrote: The GC does delete them automatically, but that doesn't happen immediately.

PHP has a gc_probability, gc_divisor session INI settings which form a "chance" value for the garbage collector to run during a request. Then, when it runs, it would delete sessions that haven't been used for more time than what is configured as gc_maxlifetime.

It's a bit confusing a first, but this is necessary for performance reasons, don't worry about it - old sessions will be deleted after some time, just as long as you don't have a gc_probability of 0.

In debian (i think) is the default value 0
Reply
#4

Guys, I have tweaked with session config & can see that GC does delete them automatically.
Reply
#5

Actually if you want there is a way to immediately remove sessions from the server, as they are kept in files. It's not recommended to do so but It's possible. Check out this link: http://php.net/manual/en/function.session-save-path.php
Reply
#6

(09-03-2015, 12:44 AM)Vita Wrote: Actually if you want there is a way to immediately remove sessions from the server, as they are kept in files. It's not recommended to do so but It's possible. Check out this link: http://php.net/manual/en/function.session-save-path.php

How the sessions are saved depends on the driver in use, which is why you should adjust the settings mentioned earlier. If your host won't permit you to change the settings and you have verified that the settings will not permit the GC to run, then you might need to resort to some other form of GC.
Reply
#7

(09-02-2015, 09:18 PM)amit Wrote: Guys, I have tweaked with session config & can see that GC does delete them automatically.

It would be nice if you also could tell us 'guys' how you tweaked. Maybe we can learn from this too.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB