Skip to content

Commit

Permalink
Merge pull request php-memcached-dev#30 from gureedo/master
Browse files Browse the repository at this point in the history
session replication feature
  • Loading branch information
iliaal committed Nov 3, 2012
2 parents 3574b28 + cc7b0de commit 1f3ae25
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions memcached.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ memcached.sess_prefix = "memc.sess.key."
; memcached session binary mode
memcached.sess_binary = Off

; memcached session number of replicas
memcached.sess_number_of_replicas = 0

; memcached session replica read randomize
memcached.sess_randomize_replica_read = Off

; Set the compression type
; valid values are: fastlz, zlib
; the default is fastlz
Expand Down
4 changes: 4 additions & 0 deletions php_memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ PHP_INI_BEGIN()
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)
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)
STD_PHP_INI_ENTRY("memcached.sess_randomize_replica_read", "0", PHP_INI_ALL, OnUpdateBool, sess_randomize_replica_read, zend_php_memcached_globals, php_memcached_globals)
#endif
STD_PHP_INI_ENTRY("memcached.compression_type", "fastlz", PHP_INI_ALL, OnUpdateCompressionType, compression_type, zend_php_memcached_globals, php_memcached_globals)
STD_PHP_INI_ENTRY("memcached.compression_factor", "1.3", PHP_INI_ALL, OnUpdateReal, compression_factor, zend_php_memcached_globals, php_memcached_globals)
Expand Down Expand Up @@ -3039,6 +3041,8 @@ static void php_memc_init_globals(zend_php_memcached_globals *php_memcached_glob
MEMC_G(sess_locked) = 0;
MEMC_G(sess_lock_key) = NULL;
MEMC_G(sess_lock_key_len) = 0;
MEMC_G(sess_number_of_replicas) = 0;
MEMC_G(sess_randomize_replica_read) = 0;
#endif
MEMC_G(serializer_name) = NULL;
MEMC_G(serializer) = SERIALIZER_DEFAULT;
Expand Down
2 changes: 2 additions & 0 deletions php_memcached.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ ZEND_BEGIN_MODULE_GLOBALS(php_memcached)
zend_bool sess_locked;
char* sess_lock_key;
int sess_lock_key_len;
int sess_number_of_replicas;
zend_bool sess_randomize_replica_read;
#endif
char *serializer_name;
enum memcached_serializer serializer;
Expand Down
11 changes: 11 additions & 0 deletions php_memcached_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ PS_OPEN_FUNC(memcached)
}
}

if (MEMC_G(sess_number_of_replicas) > 0) {
if (memcached_behavior_set(memc_sess->memc_sess, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, (uint64_t) MEMC_G(sess_number_of_replicas)) == MEMCACHED_FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to set memcached session number of replicas");
return FAILURE;
}
if (memcached_behavior_set(memc_sess->memc_sess, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ, (uint64_t) MEMC_G(sess_randomize_replica_read)) == MEMCACHED_FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to set memcached session randomize replica read");
return FAILURE;
}
}

return SUCCESS;
}
}
Expand Down

0 comments on commit 1f3ae25

Please sign in to comment.