Welcome Guest, Not a member yet? Register   Sign In
Session with DB... 1) how often is database garbage collected, 2) should i use sess_destroy or unset
#1

[eluser]inktri[/eluser]
Two questions about the default Sessions library using a database

1.) How are records in the sessions db deleted? Is there a way to have session records be deleted based on the value of the last_activity field (ie. whenever garbage collection is run, delete all records with last_activity > X hours ago)?

2.) I use the sessions class only to hold one variable. My CI script calls

Code:
set_userdata($username)

on the user's username whenever he/she logs in. And when he/she logs out, all I do is
Code:
unset_userdata($username)
. What's the downside to doing this as opposed to sess_destroying upon logout? I can see a benefit in doing so: there will be less records in the session table
#2

[eluser]Référencement Google[/eluser]
I try to answer your first question.

You don't have to think about cleaning the session garbage, this is done automatically.
It seems that the garbage cleaning frequency is totally random. The code in the Session library have this:
Code:
srand(time());
        if ((rand() % 100) < $this->gc_probability)
        {
            $expire = $this->now - $this->sess_expiration;
            
            $this->CI->db->where("last_activity < {$expire}");
            $this->CI->db->delete($this->sess_table_name);

            log_message('debug', 'Session garbage collection performed.');
        }




Theme © iAndrew 2016 - Forum software by © MyBB