Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add connect timeout option to memcached.ini #45

Merged
merged 4 commits into from Mar 3, 2013
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions memcached.ini
Expand Up @@ -47,6 +47,11 @@ memcached.sess_number_of_replicas = 0
; memcached session replica read randomize ; memcached session replica read randomize
memcached.sess_randomize_replica_read = Off memcached.sess_randomize_replica_read = Off


; memcached connect timeout value
; In non-blocking mode this changes the value of the timeout
; during socket connection in milliseconds. Specifying -1 means an infinite timeout.
memcached.sess_connect_timeout = 1000

; Set the compression type ; Set the compression type
; valid values are: fastlz, zlib ; valid values are: fastlz, zlib
; the default is fastlz ; the default is fastlz
Expand Down
3 changes: 2 additions & 1 deletion php_memcached.c
Expand Up @@ -294,6 +294,7 @@ PHP_INI_BEGIN()
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) 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)
STD_PHP_INI_ENTRY("memcached.sess_consistent_hashing", "0", PHP_INI_ALL, OnUpdateBool, sess_consistent_hashing_enabled, zend_php_memcached_globals, php_memcached_globals) STD_PHP_INI_ENTRY("memcached.sess_consistent_hashing", "0", PHP_INI_ALL, OnUpdateBool, sess_consistent_hashing_enabled, zend_php_memcached_globals, php_memcached_globals)
STD_PHP_INI_ENTRY("memcached.sess_remove_failed", "0", PHP_INI_ALL, OnUpdateBool, sess_remove_failed_enabled, zend_php_memcached_globals, php_memcached_globals) STD_PHP_INI_ENTRY("memcached.sess_remove_failed", "0", PHP_INI_ALL, OnUpdateBool, sess_remove_failed_enabled, zend_php_memcached_globals, php_memcached_globals)
STD_PHP_INI_ENTRY("memcached.sess_connect_timeout", "1000", PHP_INI_ALL, OnUpdateLong, sess_connect_timeout, zend_php_memcached_globals, php_memcached_globals)
#endif #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_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) 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 @@ -3050,8 +3051,8 @@ static void php_memc_init_globals(zend_php_memcached_globals *php_memcached_glob
MEMC_G(sess_locked) = 0; MEMC_G(sess_locked) = 0;
MEMC_G(sess_lock_key) = NULL; MEMC_G(sess_lock_key) = NULL;
MEMC_G(sess_lock_key_len) = 0; MEMC_G(sess_lock_key_len) = 0;
MEMC_G(sess_number_of_replicas) = 0;
MEMC_G(sess_randomize_replica_read) = 0; MEMC_G(sess_randomize_replica_read) = 0;
MEMC_G(sess_connect_timeout) = 1000;
#endif #endif
MEMC_G(serializer_name) = NULL; MEMC_G(serializer_name) = NULL;
MEMC_G(serializer) = SERIALIZER_DEFAULT; MEMC_G(serializer) = SERIALIZER_DEFAULT;
Expand Down
1 change: 1 addition & 0 deletions php_memcached.h
Expand Up @@ -71,6 +71,7 @@ ZEND_BEGIN_MODULE_GLOBALS(php_memcached)
zend_bool sess_randomize_replica_read; zend_bool sess_randomize_replica_read;
zend_bool sess_remove_failed_enabled; zend_bool sess_remove_failed_enabled;
zend_bool sess_consistent_hashing_enabled; zend_bool sess_consistent_hashing_enabled;
long sess_connect_timeout;
#endif #endif
char *serializer_name; char *serializer_name;
enum memcached_serializer serializer; enum memcached_serializer serializer;
Expand Down
5 changes: 5 additions & 0 deletions php_memcached_session.c
Expand Up @@ -234,6 +234,11 @@ PS_OPEN_FUNC(memcached)
return FAILURE; return FAILURE;
} }
} }

if (memcached_behavior_set(memc_sess->memc_sess, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, (uint64_t) MEMC_G(sess_connect_timeout)) == MEMCACHED_FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to set memcached connection timeout");
return FAILURE;
}


/* Allow libmemcached remove failed servers */ /* Allow libmemcached remove failed servers */
if (MEMC_G(sess_remove_failed_enabled)) { if (MEMC_G(sess_remove_failed_enabled)) {
Expand Down