Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow session garbace collection percentage to be configured. #1549

Merged
merged 3 commits into from Jul 1, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 4 additions & 7 deletions system/libraries/Session.php
Expand Up @@ -155,12 +155,6 @@ class CI_Session {
*/
public $time_reference = 'local';

/**
* Probablity level of garbage collection of old sessions
*
* @var int
*/
public $gc_probability = 5;

/**
* Session data
Expand Down Expand Up @@ -940,8 +934,11 @@ protected function _sess_gc()
return;
}

$probability = ini_get('session.gc_probability');
$divisor = ini_get('session.gc_divisor');

srand(time());
if ((rand() % 100) < $this->gc_probability)
if ((mt_rand(0, $divisor) / $divisor) < $probability)
{
$expire = $this->now - $this->sess_expiration;

Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/changelog.rst
Expand Up @@ -136,7 +136,7 @@ Release Date: Not Released
- Added unbuffered_row() method for getting a row without prefetching whole result (consume less memory).

- Libraries

- CI_Session now respects php.ini's session.gc_probability and session.gc_divisor
- Added max_filename_increment config setting for Upload library.
- CI_Loader::_ci_autoloader() is now a protected method.
- Added custom filename to Email::attach() as $this->email->attach($filename, $disposition, $newname).
Expand Down