Welcome Guest, Not a member yet? Register   Sign In
Session Garbage Collection Problem
#1

[eluser]ShoKatoo[/eluser]
Ok... so this is my first post here... but it's not my first CI application...
I'll start by saying that I'm trying to do something awesome... at least from my point of view...
This is what I've done to test my problem:
1. I installed and configured my local WAMP server corectly on a fresh Windows installation;
2. I installed a fresh copy of CI and configured it as follows:
config.php
Code:
$config['index_page'] = "";

$config['sess_cookie_name']        = 'ci_session';
$config['sess_expiration']        = 20;
$config['sess_encrypt_cookie']    = FALSE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']        = 'ci_session';
$config['sess_match_ip']        = TRUE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']     = 10;

$config['time_reference'] = 'local';
the sess_expiration and sess_time_to_update are so low to quickly simulate a expired session and to activate garbage collection.

3. I wrote 3 functions in welcome.php to test my ideea:
Code:
function login(){
    $sessData = array(
        'username'  => 'johndoe',
        'auth_status' => TRUE
    );
    $this->session->set_userdata($sessData);
    echo('you are now logged in');
}
function auth_test(){
    if($this->session->userdata('auth_status')){
        echo('you are logged in');
    }else{
        echo('you are NOT logged in');
    }
}
function logout(){
    $this->session->sess_destroy();
    echo('you are logged out');
}
then I do this:
a) I call the login() function; (result: OK)
b) check to see that I am trully logged in (auth_test(), cookie in browser, entry in DB) (result: all OK)
now 2 things can happen: call logout() function or wait 20sec for session to expire
c1) calling logout() function goes as planned (cookie is gone as is the entry from the DB) (result; OK)
c2) here comes the problem: I wait 20sec for session to expire then call the auth_test() function. The cookie in the browser is renewed but in DB there are now 2 entries: one with my old userdata (that should be gone at this point) and the new one with no userdata. Further more, every time i call the auth_test() function to check the login status, if I exceed those 20sec set for session expire, I get a new entry in the DB.

By now you should see my problem... if not I'll tell you: image that after some time my session table will be full of old entries.

Could anyone advise me if and what am I doing wrong? Is it me or is it CI?
#2

[eluser]WanWizard[/eluser]
The default GC probability is set to 5%, which means there's a 1 in 20 chance of garbage collection starting.

However, this is an average, in reality it could be quite some time before GC kicks in.

To increase the GC probability, change
Code:
$this->session->gc_probability
to a value higher that 5 (max value = 100).
#3

[eluser]ShoKatoo[/eluser]
oh... is that it? Thanks! I will investigate deeper Smile
#4

[eluser]Narkboy[/eluser]
Side note; running GC with every request will add a lot of overhead, and is not required, hence the probability default of 5%.

/B




Theme © iAndrew 2016 - Forum software by © MyBB