Skip to content

Commit a73cd49

Browse files
author
Mikko Koppanen
committed
Merge pull request #91 from merrill-oakland/sessionlocks
More granular session locking support
2 parents 98fed8d + b0cdcb3 commit a73cd49

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

memcached.ini

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ memcached.sess_locking = On
1212
; the default is 150000
1313
memcached.sess_lock_wait = 150000
1414

15+
; The maximum time, in seconds, to wait for a session lock
16+
; before timing out.
17+
; Setting to 0 results in default behavior, which is to
18+
; use max_execution_time.
19+
memcached.sess_lock_max_wait = 0;
20+
21+
; The time, in seconds, before a lock should release itself.
22+
; Setting to 0 results in the default behaviour, which is to
23+
; use the memcached.sess_lock_max_wait setting. If that is
24+
; also 0, max_execution_time will be used.
25+
memcached.sess_lock_expire = 0;
26+
1527
; memcached session key prefix
1628
; valid values are strings less than 219 bytes long
1729
; the default value is "memc.sess.key."

php_memcached.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ PHP_INI_BEGIN()
295295
STD_PHP_INI_ENTRY("memcached.sess_consistent_hash", "0", PHP_INI_ALL, OnUpdateBool, sess_consistent_hash_enabled, zend_php_memcached_globals, php_memcached_globals)
296296
STD_PHP_INI_ENTRY("memcached.sess_binary", "0", PHP_INI_ALL, OnUpdateBool, sess_binary_enabled, zend_php_memcached_globals, php_memcached_globals)
297297
STD_PHP_INI_ENTRY("memcached.sess_lock_wait", "150000", PHP_INI_ALL, OnUpdateLongGEZero,sess_lock_wait, zend_php_memcached_globals, php_memcached_globals)
298+
STD_PHP_INI_ENTRY("memcached.sess_lock_max_wait", "0", PHP_INI_ALL, OnUpdateLongGEZero, sess_lock_max_wait, zend_php_memcached_globals, php_memcached_globals)
299+
STD_PHP_INI_ENTRY("memcached.sess_lock_expire", "0", PHP_INI_ALL, OnUpdateLongGEZero, sess_lock_expire, zend_php_memcached_globals, php_memcached_globals)
298300
STD_PHP_INI_ENTRY("memcached.sess_prefix", "memc.sess.key.", PHP_INI_ALL, OnUpdateString, sess_prefix, zend_php_memcached_globals, php_memcached_globals)
299301

300302
STD_PHP_INI_ENTRY("memcached.sess_number_of_replicas", "0", PHP_INI_ALL, OnUpdateLongGEZero, sess_number_of_replicas, zend_php_memcached_globals, php_memcached_globals)
@@ -3155,6 +3157,8 @@ static void php_memc_init_globals(zend_php_memcached_globals *php_memcached_glob
31553157
MEMC_G(sess_remove_failed_enabled) = 0;
31563158
MEMC_G(sess_prefix) = NULL;
31573159
MEMC_G(sess_lock_wait) = 0;
3160+
MEMC_G(sess_lock_max_wait) = 0;
3161+
MEMC_G(sess_lock_expire) = 0;
31583162
MEMC_G(sess_locked) = 0;
31593163
MEMC_G(sess_lock_key) = NULL;
31603164
MEMC_G(sess_lock_key_len) = 0;

php_memcached.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ ZEND_BEGIN_MODULE_GLOBALS(php_memcached)
6262
#ifdef HAVE_MEMCACHED_SESSION
6363
zend_bool sess_locking_enabled;
6464
long sess_lock_wait;
65+
long sess_lock_max_wait;
66+
long sess_lock_expire;
6567
char* sess_prefix;
6668
zend_bool sess_locked;
6769
char* sess_lock_key;

php_memcached_session.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,25 @@ static int php_memc_sess_lock(memcached_st *memc, const char *key TSRMLS_DC)
4949
int lock_key_len = 0;
5050
unsigned long attempts;
5151
long write_retry_attempts = 0;
52-
long lock_maxwait;
52+
long lock_maxwait = MEMC_G(sess_lock_max_wait);
5353
long lock_wait = MEMC_G(sess_lock_wait);
54+
long lock_expire = MEMC_G(sess_lock_expire);
5455
time_t expiration;
5556
memcached_return status;
5657
/* set max timeout for session_start = max_execution_time. (c) Andrei Darashenka, Richter & Poweleit GmbH */
57-
58-
lock_maxwait = zend_ini_long(ZEND_STRS("max_execution_time"), 0);
5958
if (lock_maxwait <= 0) {
60-
lock_maxwait = MEMC_SESS_LOCK_EXPIRATION;
59+
lock_maxwait = zend_ini_long(ZEND_STRS("max_execution_time"), 0);
60+
if (lock_maxwait <= 0) {
61+
lock_maxwait = MEMC_SESS_LOCK_EXPIRATION;
62+
}
6163
}
6264
if (lock_wait == 0) {
6365
lock_wait = MEMC_SESS_DEFAULT_LOCK_WAIT;
6466
}
65-
expiration = time(NULL) + lock_maxwait + 1;
67+
if (lock_expire <= 0) {
68+
lock_expire = lock_maxwait;
69+
}
70+
expiration = time(NULL) + lock_expire + 1;
6671
attempts = (unsigned long)((1000000.0 / lock_wait) * lock_maxwait);
6772

6873
/* Set the number of write retry attempts to the number of replicas times the number of attempts to remove a server */

0 commit comments

Comments
 (0)