From 68b9b822b674e9f98025165a9391110a33f1b094 Mon Sep 17 00:00:00 2001 From: Christopher Guiney Date: Thu, 28 Jun 2012 21:53:12 -0700 Subject: Allow session garbace collection percentage to be configured. --- system/libraries/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Session.php') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 72a942b8a..4e5e256a1 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -201,7 +201,7 @@ class CI_Session { // Set all the session preferences, which can either be set // manually via the $params array above or via the config file - foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) + foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key', 'gc_probability') as $key) { $this->$key = isset($params[$key]) ? $params[$key] : $this->CI->config->item($key); } -- cgit v1.2.3-24-g4f1b From 7a14286feddcb14d3b49d2d7c83b776285946fb4 Mon Sep 17 00:00:00 2001 From: Christopher Guiney Date: Fri, 29 Jun 2012 20:34:28 -0700 Subject: Respect php.ini's values for calculating the probability of a session gc --- system/libraries/Session.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'system/libraries/Session.php') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 4e5e256a1..af38dc366 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -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 @@ -201,7 +195,7 @@ class CI_Session { // Set all the session preferences, which can either be set // manually via the $params array above or via the config file - foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key', 'gc_probability') as $key) + foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) { $this->$key = isset($params[$key]) ? $params[$key] : $this->CI->config->item($key); } @@ -940,8 +934,11 @@ class CI_Session { 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; -- cgit v1.2.3-24-g4f1b