Welcome Guest, Not a member yet? Register   Sign In
DB Session Issue
#1

[eluser]Gonzo2[/eluser]
I am facing a DB Session issue. Here are my Config environment:

$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 3600;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;



Ok, The session are successfully getting stored into a database and when I use sess_destroy() at the time of logout it delete the record from the session table, but the problem is when I am using the option of $config['sess_expire_on_close'] = TRUE it kills the session on browser window close but the record entry remains in the session table.

CI Session Wiki says:
Note: The Session class has built-in garbage collection which clears out expired sessions so you do not need to write your own routine to do it.

But, I am having left-over entries into the session table even after their expiry and only gets deleted when I use sess_destroy() not working for sess_expire_on_close.

Lots of garbage collection at session table, seem like I need to write a routine to purge the table for expired sessions.

What could be wrong here?


Gonzo
#2

[eluser]WanWizard[/eluser]
Garbage collection happens at random, based on a probability percentage, which default is 5%. It also happens automatically and in the background, it is not something you should worry about.
#3

[eluser]Gonzo2[/eluser]
Thanks WanWizard.

I see. Is there a way to call or override the process manually? just for the knowledge sake.

Gonzo
#4

[eluser]WanWizard[/eluser]
The session library has a property called "gc_probability", which is set to 5 ( so there's a 1 in 20 chance GC will run).
You can extend the session library, and alter this value.

Note that GC runs from the library constructor, so you have to define the new value either as a MY_Session class property, or alter it in the constructor before calling parent::__construct().
#5

[eluser]Gonzo2[/eluser]
Thanks again WanWizard.

I guess its better to extend Session class with MY_Session, as this way I can keep track of my changes.

Gonzo
#6

[eluser]WanWizard[/eluser]
Yes.

Modifying core files is never a good idea, upgrading to a newer version might cause a merge nightmare (which is the reason extensions exist)...




Theme © iAndrew 2016 - Forum software by © MyBB