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

[eluser]jasongodoy[/eluser]
Hey everyone...I'm getting into CI sessions and I'm looking for more information regarding Session Garbage Collection. The User Guide states
Quote: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.
which is fine, but I'd like to know more. What does garbage collection really mean? Does it mean that session records in my session table will be deleted automatically? If so, are there any settings for this kind of functionality? Look forward to learning more about this.

Thanks in advance,

J
#2

[eluser]tomdelonge[/eluser]
Yes, records are deleted automatically. The way it works is, each time the session class is loaded, a number is picked at random. I think it's a 5% chance or something, but if it's within the probability threshold (which you can change) then all records older than your settings say to be are deleted. If you raise the probability, your table will be more "up to date" but every session load will have more db queries which slows performance a little. I'd say the default settings work great for the garbage collection.
#3

[eluser]jasongodoy[/eluser]
[quote author="tomdelonge" date="1270025437"]Yes, records are deleted automatically. The way it works is, each time the session class is loaded, a number is picked at random. I think it's a 5% chance or something, but if it's within the probability threshold (which you can change) then all records older than your settings say to be are deleted. If you raise the probability, your table will be more "up to date" but every session load will have more db queries which slows performance a little. I'd say the default settings work great for the garbage collection.[/quote]

Thanks for your input. Much appreciated! :-)

J
#4

[eluser]purerj[/eluser]
Is there a way to turn the Session Garbage Collection off? Also, where can I change the settings of this feature?
#5

[eluser]danmontgomery[/eluser]
You can set $config['sess_expiration'] to 0 in config.php so that sessions never expire.
#6

[eluser]mddd[/eluser]
You could set the session expiration to a long time -- that way, sessions will not be deleted (the number is in seconds).
Set this in /application/config/config.php:
Code:
$config['sess_expiration']        = 7200;

If you set the number to 0, the system will use an expiration of 2 years (which, practically, is like forever).

Or you could set the garbage collection probability to a number below 0. That will prevent sessions from being cleaned up, regardless of session expiration.
You can do so by changing the following line in /system/libraries/Session.php.
Code:
var $gc_probability                = 5;
But of course, that could cause problems as the session database will continue to grow.
#7

[eluser]purerj[/eluser]
Thank you both for your swift responses. You were both very helpful Smile

<333 CI




Theme © iAndrew 2016 - Forum software by © MyBB