MDL-57477 session: Comment tidyup
This commit is contained in:
@@ -36,19 +36,23 @@ defined('MOODLE_INTERNAL') || die();
|
||||
class memcached extends handler {
|
||||
/** @var string $savepath save_path string */
|
||||
protected $savepath;
|
||||
|
||||
/** @var array $servers list of servers parsed from save_path */
|
||||
protected $servers;
|
||||
|
||||
/** @var string $prefix session key prefix */
|
||||
protected $prefix;
|
||||
|
||||
/** @var int $acquiretimeout how long to wait for session lock */
|
||||
protected $acquiretimeout = 120;
|
||||
|
||||
/**
|
||||
* @var int $lockexpire how long to wait before expiring the lock so that other requests
|
||||
* may continue execution, ignored if PECL memcached is below version 2.2.0.
|
||||
*/
|
||||
protected $lockexpire = 7200;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var integer $lockretrysleep Used for memcached 3.x (PHP7), the amount of time to
|
||||
* sleep between attempts to acquire the session lock. Mimics the deprecated config
|
||||
* memcached.sess_lock_wait.
|
||||
@@ -109,7 +113,6 @@ class memcached extends handler {
|
||||
|
||||
$result = parent::start();
|
||||
|
||||
// MDL-53713...
|
||||
// If session_start returned TRUE, but it took as long
|
||||
// as the timeout value, and the $_SESSION returned is
|
||||
// empty when should not have been (isnewsession false)
|
||||
@@ -148,34 +151,27 @@ class memcached extends handler {
|
||||
ini_set('memcached.sess_locking', '1'); // Locking is required!
|
||||
ini_set('memcached.sess_lock_expire', $this->lockexpire);
|
||||
|
||||
// MDL-57477, MDL-53713...
|
||||
if (version_compare($version, '3.0.0-dev') >= 0) {
|
||||
// With memcached 3.x (PHP 7) we configure the max retries to make
|
||||
// and the time to sleep between each retry. There are two sleep
|
||||
// config values, an initial and a max value. After each attempt
|
||||
// the memcached module adjusts the sleep value to be the lesser of
|
||||
// the configured max value, or 2X the previous value. With default
|
||||
// memcached.ini configs (5, 1s, 2s) the result is only 5 attempts
|
||||
// to lock over 9 sec. To mimic the behavior of the 2.2.x module so
|
||||
// we get more attempts and much more frequently, config both sleep
|
||||
// values to the old default value of 150 msec (making it constant)
|
||||
// and calculate number of retries using the existing Moodle config
|
||||
// $CFG->session_memcached_acquire_lock_timeout. Doing this so
|
||||
// admins configure session lock attempt timeout in familiar terms,
|
||||
// and more straight-forward to detect if lock attempt timeout has
|
||||
// occurred in start(). If _min and _max values are not equal, the
|
||||
// actual lock acquire timeout will not be the expected configured
|
||||
// value in $CFG->session_memcached_acquire_lock_timeout; this will
|
||||
// cause session data loss when failure to acquire the lock is not
|
||||
// detected.
|
||||
// With memcached 3.x (PHP 7) we configure the max retries to make and the time to sleep between each retry.
|
||||
// There are two sleep config values, an initial and a max value.
|
||||
// After each attempt the memcached module adjusts the sleep value to be the lesser of the configured max
|
||||
// value, or 2X the previous value.
|
||||
// With default memcached.ini configs (5, 1s, 2s) the result is only 5 attempts to lock over 9 sec.
|
||||
// To mimic the behavior of the 2.2.x module so we get more attempts and much more frequently, config both
|
||||
// sleep values to the old default value of 150 msec (making it constant) and calculate number of retries
|
||||
// using the existing Moodle config $CFG->session_memcached_acquire_lock_timeout.
|
||||
// Doing this so admins configure session lock attempt timeout in familiar terms, and more straight-forward
|
||||
// to detect if lock attempt timeout has occurred in start().
|
||||
// If _min and _max values are not equal, the actual lock acquire timeout will not be the expected
|
||||
// configured value in $CFG->session_memcached_acquire_lock_timeout; this will cause session data loss when
|
||||
// failure to acquire the lock is not detected.
|
||||
ini_set('memcached.sess_lock_wait_min', $this->lockretrysleep);
|
||||
ini_set('memcached.sess_lock_wait_max', $this->lockretrysleep);
|
||||
ini_set('memcached.sess_lock_retries', (int)(($this->acquiretimeout * 1000) / $this->lockretrysleep) + 1);
|
||||
} else {
|
||||
// With memcached 2.2.x we configure max time to attempt lock, and
|
||||
// accept default value (in memcached.ini) for sleep time between
|
||||
// each attempt (usually 150 msec), then memcached calculates the
|
||||
// max number of retries to make.
|
||||
// With memcached 2.2.x we configure max time to attempt lock, and accept default value (in memcached.ini)
|
||||
// for sleep time between each attempt (usually 150 msec), then memcached calculates the max number of
|
||||
// retries to make.
|
||||
ini_set('memcached.sess_lock_max_wait', $this->acquiretimeout);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user