Permalink
Browse files

Merge pull request #23 from dclaisse/session_consistent_hashing

add consistent hashing option for session handling
  • Loading branch information...
2 parents 7e144fa + be3253c commit 1162d10312b535fe68407e4d1bedd9d410c37c35 @iliaal iliaal committed Nov 3, 2012
Showing with 22 additions and 0 deletions.
  1. +8 −0 memcached.ini
  2. +1 −0 php_memcached.c
  3. +1 −0 php_memcached.h
  4. +12 −0 php_memcached_session.c
View
@@ -17,6 +17,14 @@ memcached.sess_lock_wait = 150000
; the default value is "memc.sess.key."
memcached.sess_prefix = "memc.sess.key."
+; memcached session consistent hash mode
+; if set to On, consistent hashing (libketama) is used
+; for session handling.
+; When consistent hashing is used, one can add or remove cache
+; node(s) without messing up too much with existing keys
+; default is Off
+memcached.sess_consistent_hash = Off
+
; memcached session binary mode
memcached.sess_binary = Off
View
@@ -285,6 +285,7 @@ static PHP_INI_MH(OnUpdateSerializer)
PHP_INI_BEGIN()
#ifdef HAVE_MEMCACHED_SESSION
STD_PHP_INI_ENTRY("memcached.sess_locking", "1", PHP_INI_ALL, OnUpdateBool, sess_locking_enabled, zend_php_memcached_globals, php_memcached_globals)
+ 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_prefix", "memc.sess.key.", PHP_INI_ALL, OnUpdateString, sess_prefix, zend_php_memcached_globals, php_memcached_globals)
View
@@ -80,6 +80,7 @@ ZEND_BEGIN_MODULE_GLOBALS(php_memcached)
#if HAVE_MEMCACHED_SASL
bool use_sasl;
#endif
+ zend_bool sess_consistent_hash_enabled;
zend_bool sess_binary_enabled;
ZEND_END_MODULE_GLOBALS(php_memcached)
View
@@ -139,6 +139,18 @@ PS_OPEN_FUNC(memcached)
if (servers) {
memc_sess->memc_sess = memcached_create(NULL);
if (memc_sess->memc_sess) {
+ if (MEMC_G(sess_consistent_hash_enabled)) {
+ if (memcached_behavior_set(memc_sess->memc_sess, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, (uint64_t) 1) == MEMCACHED_FAILURE) {
+ PS_SET_MOD_DATA(NULL);
+ if (plist_key) {
+ efree(plist_key);
+ }
+ memcached_free(memc_sess->memc_sess);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to enable memcached consistent hashing");
+ return FAILURE;
+ }
+ }
+
status = memcached_server_push(memc_sess->memc_sess, servers);
memcached_server_list_free(servers);

0 comments on commit 1162d10

Please sign in to comment.