Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions memcached.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ memcached.sess_locking = On
; the default is 150000
memcached.sess_lock_wait = 150000

; The maximum time, in seconds, to wait for a session lock
; before timing out.
; Setting to 0 results in default behavior, which is to
; use max_execution_time.
memcached.sess_lock_max_wait = 0;

; The time, in seconds, before a lock should release itself.
; Setting to 0 results in the default behaviour, which is to
; use the memcached.sess_lock_max_wait setting. If that is
; also 0, max_execution_time will be used.
memcached.sess_lock_expire = 0;

; memcached session key prefix
; valid values are strings less than 219 bytes long
; the default value is "memc.sess.key."
Expand Down
4 changes: 4 additions & 0 deletions php_memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("memcached.sess_consistent_hash", "0", PHP_INI_ALL, OnUpdateBool, sess_consistent_hash_enabled, zend_php_memcached_globals, php_memcached_globals)
STD_PHP_INI_ENTRY("memcached.sess_binary", "0", PHP_INI_ALL, OnUpdateBool, sess_binary_enabled, zend_php_memcached_globals, php_memcached_globals)
STD_PHP_INI_ENTRY("memcached.sess_lock_wait", "150000", PHP_INI_ALL, OnUpdateLongGEZero,sess_lock_wait, zend_php_memcached_globals, php_memcached_globals)
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)
STD_PHP_INI_ENTRY("memcached.sess_lock_expire", "0", PHP_INI_ALL, OnUpdateLongGEZero, sess_lock_expire, zend_php_memcached_globals, php_memcached_globals)
STD_PHP_INI_ENTRY("memcached.sess_prefix", "memc.sess.key.", PHP_INI_ALL, OnUpdateString, sess_prefix, zend_php_memcached_globals, php_memcached_globals)

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)
Expand Down Expand Up @@ -3155,6 +3157,8 @@ static void php_memc_init_globals(zend_php_memcached_globals *php_memcached_glob
MEMC_G(sess_remove_failed_enabled) = 0;
MEMC_G(sess_prefix) = NULL;
MEMC_G(sess_lock_wait) = 0;
MEMC_G(sess_lock_max_wait) = 0;
MEMC_G(sess_lock_expire) = 0;
MEMC_G(sess_locked) = 0;
MEMC_G(sess_lock_key) = NULL;
MEMC_G(sess_lock_key_len) = 0;
Expand Down
2 changes: 2 additions & 0 deletions php_memcached.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ ZEND_BEGIN_MODULE_GLOBALS(php_memcached)
#ifdef HAVE_MEMCACHED_SESSION
zend_bool sess_locking_enabled;
long sess_lock_wait;
long sess_lock_max_wait;
long sess_lock_expire;
char* sess_prefix;
zend_bool sess_locked;
char* sess_lock_key;
Expand Down
15 changes: 10 additions & 5 deletions php_memcached_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,25 @@ static int php_memc_sess_lock(memcached_st *memc, const char *key TSRMLS_DC)
int lock_key_len = 0;
unsigned long attempts;
long write_retry_attempts = 0;
long lock_maxwait;
long lock_maxwait = MEMC_G(sess_lock_max_wait);
long lock_wait = MEMC_G(sess_lock_wait);
long lock_expire = MEMC_G(sess_lock_expire);
time_t expiration;
memcached_return status;
/* set max timeout for session_start = max_execution_time. (c) Andrei Darashenka, Richter & Poweleit GmbH */

lock_maxwait = zend_ini_long(ZEND_STRS("max_execution_time"), 0);
if (lock_maxwait <= 0) {
lock_maxwait = MEMC_SESS_LOCK_EXPIRATION;
lock_maxwait = zend_ini_long(ZEND_STRS("max_execution_time"), 0);
if (lock_maxwait <= 0) {
lock_maxwait = MEMC_SESS_LOCK_EXPIRATION;
}
}
if (lock_wait == 0) {
lock_wait = MEMC_SESS_DEFAULT_LOCK_WAIT;
}
expiration = time(NULL) + lock_maxwait + 1;
if (lock_expire <= 0) {
lock_expire = lock_maxwait;
}
expiration = time(NULL) + lock_expire + 1;
attempts = (unsigned long)((1000000.0 / lock_wait) * lock_maxwait);

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