diff --git a/memcached.ini b/memcached.ini index 0f1a82b0..dd405a05 100644 --- a/memcached.ini +++ b/memcached.ini @@ -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." diff --git a/php_memcached.c b/php_memcached.c index ada893f5..b9d60319 100644 --- a/php_memcached.c +++ b/php_memcached.c @@ -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) @@ -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; diff --git a/php_memcached.h b/php_memcached.h index 70e12d60..9eeb8a0e 100644 --- a/php_memcached.h +++ b/php_memcached.h @@ -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; diff --git a/php_memcached_session.c b/php_memcached_session.c index e8711d31..91d431f4 100644 --- a/php_memcached_session.c +++ b/php_memcached_session.c @@ -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 */