From f9fbf1187516363a48fe2fe7bc33d00ae11f134f Mon Sep 17 00:00:00 2001 From: Ignasimg Date: Fri, 6 Feb 2015 09:21:07 +0100 Subject: Update Input.php Added support for json input stream. (Not tested) --- system/core/Input.php | 55 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index 72425c1c1..3024fca78 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -103,6 +103,14 @@ class CI_Input { */ protected $headers = array(); + /** + * Raw input stream data + * + * @see CI_Input::input_stream() + * @var array + */ + protected $_raw_input_stream = NULL; + /** * Input stream data * @@ -111,7 +119,7 @@ class CI_Input { * @see CI_Input::input_stream() * @var array */ - protected $_input_stream = NULL; + protected $_input_stream = NULL; // Kept for backward compatible. /** * Class constructor @@ -298,6 +306,25 @@ class CI_Input { // ------------------------------------------------------------------------ + /** + * Fetch raw data from php://input stream + * + * Useful when data is not an array and might contain = and & symbols. + */ + public function raw_input_stream() + { + // Prior to PHP 5.6, the input stream can only be read once, + // so we'll need to check if we have already done that first. + if (is_null($this->_raw_input_stream)) + { + $this->_raw_input_stream = file_get_contents('php://input'); + } + + return $this->_raw_input_stream; + } + + // ------------------------------------------------------------------------ + /** * Fetch an item from the php://input stream * @@ -309,16 +336,26 @@ class CI_Input { */ public function input_stream($index = NULL, $xss_clean = NULL) { - // Prior to PHP 5.6, the input stream can only be read once, - // so we'll need to check if we have already done that first. - if ( ! is_array($this->_input_stream)) - { - parse_str(file_get_contents('php://input'), $this->_input_stream); - is_array($this->_input_stream) OR $this->_input_stream = array(); - } - + parse_str($this->raw_input_stream(), $this->_input_stream); return $this->_fetch_from_array($this->_input_stream, $index, $xss_clean); } + + // ------------------------------------------------------------------------ + + /** + * Fetch an item from the php://input stream + * + * Useful when you need to access input that's been send as raw json data' + * + * @param string $index Index for item to be fetched + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + public function json_input_stream($index = NULL, $xss_clean = NULL) + { + $json_input_stream = json_decode($this->raw_input_stream(), true); + return $this->_fetch_from_array($json_input_stream, $index, $xss_clean); + } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From a8c964c5a1d48d9a70ed5826a086e9eba9963cc9 Mon Sep 17 00:00:00 2001 From: Ignasimg Date: Thu, 19 Feb 2015 01:26:06 +0100 Subject: documentation changes --- system/core/Input.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index 3024fca78..f181c27ce 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -104,9 +104,9 @@ class CI_Input { protected $headers = array(); /** - * Raw input stream data + * Raw input stream data as received from php://input * - * @see CI_Input::input_stream() + * @see CI_Input::raw_input_stream() * @var array */ protected $_raw_input_stream = NULL; @@ -114,12 +114,12 @@ class CI_Input { /** * Input stream data * - * Parsed from php://input at runtime + * Parsed from raw_input_stream at runtime * * @see CI_Input::input_stream() * @var array */ - protected $_input_stream = NULL; // Kept for backward compatible. + protected $_input_stream = NULL; /** * Class constructor @@ -309,7 +309,7 @@ class CI_Input { /** * Fetch raw data from php://input stream * - * Useful when data is not an array and might contain = and & symbols. + * Useful when data is not an array. */ public function raw_input_stream() { @@ -326,7 +326,7 @@ class CI_Input { // ------------------------------------------------------------------------ /** - * Fetch an item from the php://input stream + * Fetch an item from the input stream * * Useful when you need to access PUT, DELETE or PATCH request data. * @@ -343,9 +343,9 @@ class CI_Input { // ------------------------------------------------------------------------ /** - * Fetch an item from the php://input stream + * Fetch an item from the input stream * - * Useful when you need to access input that's been send as raw json data' + * Useful when you need to access input that's been send as json' * * @param string $index Index for item to be fetched * @param bool $xss_clean Whether to apply XSS filtering -- cgit v1.2.3-24-g4f1b From 0b5569f11b9eab01e3b1571eb6012308a3868f01 Mon Sep 17 00:00:00 2001 From: Ignasimg Date: Fri, 20 Feb 2015 17:56:55 +0100 Subject: Added support for raw_input_stream property. --- system/core/Input.php | 81 ++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 53 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index f181c27ce..97884d309 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -103,22 +103,16 @@ class CI_Input { */ protected $headers = array(); - /** - * Raw input stream data as received from php://input - * - * @see CI_Input::raw_input_stream() - * @var array - */ protected $_raw_input_stream = NULL; /** - * Input stream data - * - * Parsed from raw_input_stream at runtime - * - * @see CI_Input::input_stream() - * @var array - */ + * Input stream data + * + * Parsed from php://input at runtime + * + * @see CI_Input::input_stream() + * @var array + */ protected $_input_stream = NULL; /** @@ -307,54 +301,35 @@ class CI_Input { // ------------------------------------------------------------------------ /** - * Fetch raw data from php://input stream - * - * Useful when data is not an array. - */ - public function raw_input_stream() + * Fetch an item from the php://input stream + * + * Useful when you need to access PUT, DELETE or PATCH request data. + * + * @param string $index Index for item to be fetched + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + public function input_stream($index = NULL, $xss_clean = NULL) { - // Prior to PHP 5.6, the input stream can only be read once, - // so we'll need to check if we have already done that first. - if (is_null($this->_raw_input_stream)) + // Prior to PHP 5.6, the input stream can only be read once, + // so we'll need to check if we have already done that first. + if ( ! is_array($this->_input_stream)) { - $this->_raw_input_stream = file_get_contents('php://input'); + parse_str($this->raw_input_stream, $this->_input_stream); + is_array($this->_input_stream) OR $this->_input_stream = array(); } - - return $this->_raw_input_stream; - } - - // ------------------------------------------------------------------------ - - /** - * Fetch an item from the input stream - * - * Useful when you need to access PUT, DELETE or PATCH request data. - * - * @param string $index Index for item to be fetched - * @param bool $xss_clean Whether to apply XSS filtering - * @return mixed - */ - public function input_stream($index = NULL, $xss_clean = NULL) - { - parse_str($this->raw_input_stream(), $this->_input_stream); return $this->_fetch_from_array($this->_input_stream, $index, $xss_clean); } - + // ------------------------------------------------------------------------ - /** - * Fetch an item from the input stream - * - * Useful when you need to access input that's been send as json' - * - * @param string $index Index for item to be fetched - * @param bool $xss_clean Whether to apply XSS filtering - * @return mixed - */ - public function json_input_stream($index = NULL, $xss_clean = NULL) + public function __get($name) { - $json_input_stream = json_decode($this->raw_input_stream(), true); - return $this->_fetch_from_array($json_input_stream, $index, $xss_clean); + if ($name === 'raw_input_stream') + { + isset($this->_raw_input_stream) OR $this->_raw_input_stream = file_get_contents('php://input'); + return $this->_raw_input_stream; + } } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From c519b26d78edb21fd189e73f0feb12690aa34f2d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 21 Feb 2015 19:20:03 +0200 Subject: Fix #3610 --- system/libraries/Session/drivers/Session_files_driver.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Session/drivers/Session_files_driver.php b/system/libraries/Session/drivers/Session_files_driver.php index 5852277e8..74528e9d2 100644 --- a/system/libraries/Session/drivers/Session_files_driver.php +++ b/system/libraries/Session/drivers/Session_files_driver.php @@ -299,7 +299,9 @@ class CI_Session_files_driver extends CI_Session_driver implements SessionHandle { if ($this->close()) { - return unlink($this->_file_path.$session_id) && $this->_cookie_destroy(); + return file_exists($this->_file_path.$session_id) + ? (unlink($this->_file_path.$session_id) && $this->_cookie_destroy()) + : TRUE; } elseif ($this->_file_path !== NULL) { -- cgit v1.2.3-24-g4f1b From bc834c327407184867f363ad58a24e6733a85b66 Mon Sep 17 00:00:00 2001 From: Fieah Date: Sun, 22 Feb 2015 17:08:35 +0800 Subject: Cache: is_supported 1. Cache_redis: Standardize the style as other driver. 2. Cache_wincache: Also check wincache.ucenabled --- system/libraries/Cache/drivers/Cache_redis.php | 8 +++----- system/libraries/Cache/drivers/Cache_wincache.php | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index f2a41cc67..5236556d9 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -243,15 +243,13 @@ class CI_Cache_redis extends CI_Driver */ public function is_supported() { - if (extension_loaded('redis')) - { - return $this->_setup_redis(); - } - else + if ( ! extension_loaded('redis')) { log_message('debug', 'The Redis extension must be loaded to use Redis cache.'); return FALSE; } + + return $this->_setup_redis(); } // ------------------------------------------------------------------------ diff --git a/system/libraries/Cache/drivers/Cache_wincache.php b/system/libraries/Cache/drivers/Cache_wincache.php index 528b2b9bf..9cc6ff016 100644 --- a/system/libraries/Cache/drivers/Cache_wincache.php +++ b/system/libraries/Cache/drivers/Cache_wincache.php @@ -194,7 +194,7 @@ class CI_Cache_wincache extends CI_Driver { */ public function is_supported() { - if ( ! extension_loaded('wincache')) + if ( ! extension_loaded('wincache') OR ! ini_get('wincache.ucenabled')) { log_message('debug', 'The Wincache PHP extension must be loaded to use Wincache Cache.'); return FALSE; -- cgit v1.2.3-24-g4f1b From b4ebb39d68797466cac74f4c2c61ea1908ce61cd Mon Sep 17 00:00:00 2001 From: Fieah Date: Sun, 22 Feb 2015 23:55:15 +0800 Subject: Common.php: set_status_header: Improve 1. Verify $code before define $stati 2. Only convert $code to int and define $stati when needed, possibly can save some memory. --- system/core/Common.php | 91 +++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 46 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index 7035c18ff..ee5a705b2 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -497,59 +497,58 @@ if ( ! function_exists('set_status_header')) return; } - $stati = array( - 200 => 'OK', - 201 => 'Created', - 202 => 'Accepted', - 203 => 'Non-Authoritative Information', - 204 => 'No Content', - 205 => 'Reset Content', - 206 => 'Partial Content', - - 300 => 'Multiple Choices', - 301 => 'Moved Permanently', - 302 => 'Found', - 303 => 'See Other', - 304 => 'Not Modified', - 305 => 'Use Proxy', - 307 => 'Temporary Redirect', - - 400 => 'Bad Request', - 401 => 'Unauthorized', - 403 => 'Forbidden', - 404 => 'Not Found', - 405 => 'Method Not Allowed', - 406 => 'Not Acceptable', - 407 => 'Proxy Authentication Required', - 408 => 'Request Timeout', - 409 => 'Conflict', - 410 => 'Gone', - 411 => 'Length Required', - 412 => 'Precondition Failed', - 413 => 'Request Entity Too Large', - 414 => 'Request-URI Too Long', - 415 => 'Unsupported Media Type', - 416 => 'Requested Range Not Satisfiable', - 417 => 'Expectation Failed', - 422 => 'Unprocessable Entity', - - 500 => 'Internal Server Error', - 501 => 'Not Implemented', - 502 => 'Bad Gateway', - 503 => 'Service Unavailable', - 504 => 'Gateway Timeout', - 505 => 'HTTP Version Not Supported' - ); - if (empty($code) OR ! is_numeric($code)) { show_error('Status codes must be numeric', 500); } - is_int($code) OR $code = (int) $code; - if (empty($text)) { + is_int($code) OR $code = (int) $code; + $stati = array( + 200 => 'OK', + 201 => 'Created', + 202 => 'Accepted', + 203 => 'Non-Authoritative Information', + 204 => 'No Content', + 205 => 'Reset Content', + 206 => 'Partial Content', + + 300 => 'Multiple Choices', + 301 => 'Moved Permanently', + 302 => 'Found', + 303 => 'See Other', + 304 => 'Not Modified', + 305 => 'Use Proxy', + 307 => 'Temporary Redirect', + + 400 => 'Bad Request', + 401 => 'Unauthorized', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Request Entity Too Large', + 414 => 'Request-URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Requested Range Not Satisfiable', + 417 => 'Expectation Failed', + 422 => 'Unprocessable Entity', + + 500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported' + ); + if (isset($stati[$code])) { $text = $stati[$code]; -- cgit v1.2.3-24-g4f1b From abc8f00465beb4cb99cc533ab2dbf3cb4191cbbe Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 23 Feb 2015 08:38:06 +0200 Subject: [ci skip] Fix #3618 --- system/libraries/Session/drivers/Session_redis_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 1cc4d75d7..5fbb5222c 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -272,7 +272,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle { if (isset($this->_redis, $this->_lock_key)) { - if ($this->_redis->delete($this->_key_prefix.$session_id) !== 1) + if (($result = $this->_redis->delete($this->_key_prefix.$session_id)) !== 1) { log_message('debug', 'Session: Redis::delete() expected to return 1, got '.var_export($result, TRUE).' instead.'); } -- cgit v1.2.3-24-g4f1b From cae95883a03b686d24b1d62191f38723ae958960 Mon Sep 17 00:00:00 2001 From: Ignasimg Date: Thu, 26 Feb 2015 02:46:14 +0100 Subject: funny tabs & spaces added and removed. --- system/core/Input.php | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index 97884d309..14f3e1083 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -103,16 +103,16 @@ class CI_Input { */ protected $headers = array(); - protected $_raw_input_stream = NULL; + protected $_raw_input_stream; /** - * Input stream data - * - * Parsed from php://input at runtime - * - * @see CI_Input::input_stream() - * @var array - */ + * Input stream data + * + * Parsed from php://input at runtime + * + * @see CI_Input::input_stream() + * @var array + */ protected $_input_stream = NULL; /** @@ -301,23 +301,25 @@ class CI_Input { // ------------------------------------------------------------------------ /** - * Fetch an item from the php://input stream - * - * Useful when you need to access PUT, DELETE or PATCH request data. - * - * @param string $index Index for item to be fetched - * @param bool $xss_clean Whether to apply XSS filtering - * @return mixed - */ + * Fetch an item from the php://input stream + * + * Useful when you need to access PUT, DELETE or PATCH request data. + * + * @param string $index Index for item to be fetched + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ public function input_stream($index = NULL, $xss_clean = NULL) { - // Prior to PHP 5.6, the input stream can only be read once, - // so we'll need to check if we have already done that first. + // Prior to PHP 5.6, the input stream can only be read once, + // so we'll need to check if we have already done that first. if ( ! is_array($this->_input_stream)) { + // $this->raw_input_stream will trigger __get(). parse_str($this->raw_input_stream, $this->_input_stream); is_array($this->_input_stream) OR $this->_input_stream = array(); } + return $this->_fetch_from_array($this->_input_stream, $index, $xss_clean); } -- cgit v1.2.3-24-g4f1b From 1e35792cc2d231cba11c2faefd71717ab67a46d2 Mon Sep 17 00:00:00 2001 From: Ignasimg Date: Thu, 26 Feb 2015 18:02:45 +0100 Subject: Update Input.php --- system/core/Input.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index 14f3e1083..a72c4ac1e 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -305,8 +305,8 @@ class CI_Input { * * Useful when you need to access PUT, DELETE or PATCH request data. * - * @param string $index Index for item to be fetched - * @param bool $xss_clean Whether to apply XSS filtering + * @param string $index Index for item to be fetched + * @param bool $xss_clean Whether to apply XSS filtering * @return mixed */ public function input_stream($index = NULL, $xss_clean = NULL) @@ -319,7 +319,7 @@ class CI_Input { parse_str($this->raw_input_stream, $this->_input_stream); is_array($this->_input_stream) OR $this->_input_stream = array(); } - + return $this->_fetch_from_array($this->_input_stream, $index, $xss_clean); } -- cgit v1.2.3-24-g4f1b From d0ac8b132390387d08bcaa5a20fbea35a350c9d3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 27 Feb 2015 11:41:52 +0200 Subject: Fix an E_NOTICE caused by #3604 --- system/core/Input.php | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index c3382b4d9..3e792fc13 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -103,17 +103,26 @@ class CI_Input { */ protected $headers = array(); + /** + * Raw input stream data + * + * Holds a cache of php://input contents + * + * @var string + */ protected $_raw_input_stream; /** - * Input stream data + * Parsed input stream data * * Parsed from php://input at runtime * * @see CI_Input::input_stream() * @var array */ - protected $_input_stream = NULL; + protected $_input_stream; + + // -------------------------------------------------------------------- /** * Class constructor @@ -325,17 +334,6 @@ class CI_Input { // ------------------------------------------------------------------------ - public function __get($name) - { - if ($name === 'raw_input_stream') - { - isset($this->_raw_input_stream) OR $this->_raw_input_stream = file_get_contents('php://input'); - return $this->_raw_input_stream; - } - } - - // ------------------------------------------------------------------------ - /** * Set cookie * @@ -860,4 +858,23 @@ class CI_Input { : strtolower($this->server('REQUEST_METHOD')); } + // ------------------------------------------------------------------------ + + /** + * Magic __get() + * + * Allows read access to protected properties + * + * @param string $name + * @return mixed + */ + public function __get($name) + { + if ($name === 'raw_input_stream') + { + isset($this->_raw_input_stream) OR $this->_raw_input_stream = file_get_contents('php://input'); + return $this->_raw_input_stream; + } + } + } -- cgit v1.2.3-24-g4f1b From 88fd8e4548eb50d8307757b8e37333ded8f221e9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 27 Feb 2015 11:43:01 +0200 Subject: Eh ... really fix that notice (#3604) --- system/core/Input.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index 3e792fc13..484397d63 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -122,6 +122,8 @@ class CI_Input { */ protected $_input_stream; + protected $security; + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From 7d365dcc8bdf69534b54401cc862be105e1a8a28 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 27 Feb 2015 14:32:15 +0200 Subject: Fix #3633 --- system/core/Input.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index 484397d63..be9f3c169 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -123,6 +123,7 @@ class CI_Input { protected $_input_stream; protected $security; + protected $uni; // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 52caf59f244e0c1363ac0ce6ba61a7f5001603df Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 27 Feb 2015 15:09:34 +0200 Subject: Make CI_Input:: read-only as well --- system/core/Input.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index be9f3c169..6be4b9a6c 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -55,7 +55,7 @@ class CI_Input { * * @var string */ - public $ip_address = FALSE; + protected $ip_address = FALSE; /** * Allow GET array flag @@ -878,6 +878,10 @@ class CI_Input { isset($this->_raw_input_stream) OR $this->_raw_input_stream = file_get_contents('php://input'); return $this->_raw_input_stream; } + elseif ($name === 'ip_address') + { + return $this->ip_address; + } } } -- cgit v1.2.3-24-g4f1b From fd08d02b1984d8f27a5e447a5c9d5e190271ab5e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 3 Mar 2015 12:36:11 +0200 Subject: Remove an unused var in CI_Log Was suggested as part of PR #3630, which was rejected due to numerous other changes --- system/core/Log.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'system') diff --git a/system/core/Log.php b/system/core/Log.php index 833316273..e8cb401f5 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -69,13 +69,6 @@ class CI_Log { */ protected $_threshold = 1; - /** - * Highest level of logging - * - * @var int - */ - protected $_threshold_max = 0; - /** * Array of threshold levels to log * @@ -139,7 +132,7 @@ class CI_Log { } elseif (is_array($config['log_threshold'])) { - $this->_threshold = $this->_threshold_max; + $this->_threshold = 0; $this->_threshold_array = array_flip($config['log_threshold']); } -- cgit v1.2.3-24-g4f1b From e1a5bb345b1b30ea777348efa9cade21c1f2e2fb Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 4 Mar 2015 13:33:39 +0200 Subject: Fix #3627: Keep timed locks for more than 5 seconds Emulated locks for Redis and Memcached now have a TTL of 300 seconds (the default HTTP request timeout value on many environments) and 30 attemps, each separated by sleep(1), are made by the blocked request to try and obtain a lock if it has been freed. Additionaly, the blocking time for MySQL's locks, which are also timed, is also set to 300 seconds. --- .../Session/drivers/Session_database_driver.php | 2 +- .../Session/drivers/Session_memcached_driver.php | 30 +++++----------- .../Session/drivers/Session_redis_driver.php | 40 +++++++--------------- 3 files changed, 23 insertions(+), 49 deletions(-) (limited to 'system') diff --git a/system/libraries/Session/drivers/Session_database_driver.php b/system/libraries/Session/drivers/Session_database_driver.php index f496b4fe0..76c1cf34e 100644 --- a/system/libraries/Session/drivers/Session_database_driver.php +++ b/system/libraries/Session/drivers/Session_database_driver.php @@ -319,7 +319,7 @@ class CI_Session_database_driver extends CI_Session_driver implements SessionHan if ($this->_platform === 'mysql') { $arg = $session_id.($this->_config['match_ip'] ? '_'.$_SERVER['REMOTE_ADDR'] : ''); - if ($this->_db->query("SELECT GET_LOCK('".$arg."', 10) AS ci_session_lock")->row()->ci_session_lock) + if ($this->_db->query("SELECT GET_LOCK('".$arg."', 300) AS ci_session_lock")->row()->ci_session_lock) { $this->_lock = $arg; return TRUE; diff --git a/system/libraries/Session/drivers/Session_memcached_driver.php b/system/libraries/Session/drivers/Session_memcached_driver.php index f1a6e2400..938a612d9 100644 --- a/system/libraries/Session/drivers/Session_memcached_driver.php +++ b/system/libraries/Session/drivers/Session_memcached_driver.php @@ -204,7 +204,7 @@ class CI_Session_memcached_driver extends CI_Session_driver implements SessionHa if (isset($this->_lock_key)) { - $this->_memcached->replace($this->_lock_key, time(), 5); + $this->_memcached->replace($this->_lock_key, time(), 300); if ($this->_fingerprint !== ($fingerprint = md5($session_data))) { if ($this->_memcached->set($this->_key_prefix.$session_id, $session_data, $this->_config['expiration'])) @@ -299,34 +299,21 @@ class CI_Session_memcached_driver extends CI_Session_driver implements SessionHa { if (isset($this->_lock_key)) { - return $this->_memcached->replace($this->_lock_key, time(), 5); + return $this->_memcached->replace($this->_lock_key, time(), 300); } + // 30 attempts to obtain a lock, in case another request already has it $lock_key = $this->_key_prefix.$session_id.':lock'; - if ( ! ($ts = $this->_memcached->get($lock_key))) - { - if ( ! $this->_memcached->set($lock_key, TRUE, 5)) - { - log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id); - return FALSE; - } - - $this->_lock_key = $lock_key; - $this->_lock = TRUE; - return TRUE; - } - - // Another process has the lock, we'll try to wait for it to free itself ... $attempt = 0; - while ($attempt++ < 5) + do { - usleep(((time() - $ts) * 1000000) - 20000); - if (($ts = $this->_memcached->get($lock_key)) < time()) + if ($this->_memcached->get($lock_key)) { + sleep(1); continue; } - if ( ! $this->_memcached->set($lock_key, time(), 5)) + if ( ! $this->_memcached->set($lock_key, time(), 300)) { log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id); return FALSE; @@ -335,8 +322,9 @@ class CI_Session_memcached_driver extends CI_Session_driver implements SessionHa $this->_lock_key = $lock_key; break; } + while ($attempt++ < 30); - if ($attempt === 5) + if ($attempt === 30) { log_message('error', 'Session: Unable to obtain lock for '.$this->_key_prefix.$session_id.' after 5 attempts, aborting.'); return FALSE; diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 5fbb5222c..1ce101daf 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -205,7 +205,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle if (isset($this->_lock_key)) { - $this->_redis->setTimeout($this->_lock_key, 5); + $this->_redis->setTimeout($this->_lock_key, 300); if ($this->_fingerprint !== ($fingerprint = md5($session_data))) { if ($this->_redis->set($this->_key_prefix.$session_id, $session_data, $this->_config['expiration'])) @@ -313,40 +313,21 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle { if (isset($this->_lock_key)) { - return $this->_redis->setTimeout($this->_lock_key, 5); + return $this->_redis->setTimeout($this->_lock_key, 300); } + // 30 attempts to obtain a lock, in case another request already has it $lock_key = $this->_key_prefix.$session_id.':lock'; - if (($ttl = $this->_redis->ttl($lock_key)) < 1) - { - if ( ! $this->_redis->setex($lock_key, 5, time())) - { - log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id); - return FALSE; - } - - $this->_lock_key = $lock_key; - - if ($ttl === -1) - { - log_message('debug', 'Session: Lock for '.$this->_key_prefix.$session_id.' had no TTL, overriding.'); - } - - $this->_lock = TRUE; - return TRUE; - } - - // Another process has the lock, we'll try to wait for it to free itself ... $attempt = 0; - while ($attempt++ < 5) + do { - usleep(($ttl * 1000000) - 20000); if (($ttl = $this->_redis->ttl($lock_key)) > 0) { + sleep(1); continue; } - if ( ! $this->_redis->setex($lock_key, 5, time())) + if ( ! $this->_redis->setex($lock_key, 300, time())) { log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id); return FALSE; @@ -355,12 +336,17 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle $this->_lock_key = $lock_key; break; } + while ($attempt++ < 30); - if ($attempt === 5) + if ($attempt === 30) { - log_message('error', 'Session: Unable to obtain lock for '.$this->_key_prefix.$session_id.' after 5 attempts, aborting.'); + log_message('error', 'Session: Unable to obtain lock for '.$this->_key_prefix.$session_id.' after 30 attempts, aborting.'); return FALSE; } + elseif ($ttl === -1) + { + log_message('debug', 'Session: Lock for '.$this->_key_prefix.$session_id.' had no TTL, overriding.'); + } $this->_lock = TRUE; return TRUE; -- cgit v1.2.3-24-g4f1b From 137aa20e0b0fd71ff8f672c57c07c4972c91c6a4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Mar 2015 11:36:25 +0200 Subject: Fix #3642 --- system/core/Config.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/core/Config.php b/system/core/Config.php index a191a7727..b9af8e3b2 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -126,7 +126,6 @@ class CI_Config { foreach (array($file, ENVIRONMENT.'/'.$file) as $location) { $file_path = $path.'config/'.$location.'.php'; - if (in_array($file_path, $this->is_loaded, TRUE)) { return TRUE; @@ -165,14 +164,13 @@ class CI_Config { $loaded = TRUE; log_message('debug', 'Config file loaded: '.$file_path); } - - if ($loaded === TRUE) - { - return TRUE; - } } - if ($fail_gracefully === TRUE) + if ($loaded === TRUE) + { + return TRUE; + } + elseif ($fail_gracefully === TRUE) { return FALSE; } -- cgit v1.2.3-24-g4f1b