Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
integration
prechecker
Commits
2a31e628
Commit
2a31e628
authored
Oct 24, 2017
by
Andrew Nicols
Browse files
MDL-57477 session: Comment tidyup
parent
79d3a1bc
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/classes/session/memcached.php
View file @
2a31e628
...
...
@@ -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
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment