Skip to content

Commit 5fb6436

Browse files
committed
Merge pull request #45 from xoJIog/master
add connect timeout option to memcached.ini
2 parents bf4f978 + d7ed677 commit 5fb6436

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

memcached.ini

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ memcached.sess_binary = Off
4444
; memcached session replica read randomize
4545
memcached.sess_randomize_replica_read = Off
4646

47+
; memcached connect timeout value
48+
; In non-blocking mode this changes the value of the timeout
49+
; during socket connection in milliseconds. Specifying -1 means an infinite timeout.
50+
memcached.sess_connect_timeout = 1000
51+
4752
; Set the compression type
4853
; valid values are: fastlz, zlib
4954
; the default is fastlz

php_memcached.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ PHP_INI_BEGIN()
294294
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)
295295
STD_PHP_INI_ENTRY("memcached.sess_consistent_hashing", "0", PHP_INI_ALL, OnUpdateBool, sess_consistent_hashing_enabled, zend_php_memcached_globals, php_memcached_globals)
296296
STD_PHP_INI_ENTRY("memcached.sess_remove_failed", "0", PHP_INI_ALL, OnUpdateBool, sess_remove_failed_enabled, zend_php_memcached_globals, php_memcached_globals)
297+
STD_PHP_INI_ENTRY("memcached.sess_connect_timeout", "1000", PHP_INI_ALL, OnUpdateLong, sess_connect_timeout, zend_php_memcached_globals, php_memcached_globals)
297298
#endif
298299
STD_PHP_INI_ENTRY("memcached.compression_type", "fastlz", PHP_INI_ALL, OnUpdateCompressionType, compression_type, zend_php_memcached_globals, php_memcached_globals)
299300
STD_PHP_INI_ENTRY("memcached.compression_factor", "1.3", PHP_INI_ALL, OnUpdateReal, compression_factor, zend_php_memcached_globals, php_memcached_globals)
@@ -3130,8 +3131,8 @@ static void php_memc_init_globals(zend_php_memcached_globals *php_memcached_glob
31303131
MEMC_G(sess_locked) = 0;
31313132
MEMC_G(sess_lock_key) = NULL;
31323133
MEMC_G(sess_lock_key_len) = 0;
3133-
MEMC_G(sess_number_of_replicas) = 0;
31343134
MEMC_G(sess_randomize_replica_read) = 0;
3135+
MEMC_G(sess_connect_timeout) = 1000;
31353136
#endif
31363137
MEMC_G(serializer_name) = NULL;
31373138
MEMC_G(serializer) = SERIALIZER_DEFAULT;

php_memcached.h

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ ZEND_BEGIN_MODULE_GLOBALS(php_memcached)
7171
zend_bool sess_randomize_replica_read;
7272
zend_bool sess_remove_failed_enabled;
7373
zend_bool sess_consistent_hashing_enabled;
74+
long sess_connect_timeout;
7475
#endif
7576
char *serializer_name;
7677
enum memcached_serializer serializer;

php_memcached_session.c

+5
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ PS_OPEN_FUNC(memcached)
234234
return FAILURE;
235235
}
236236
}
237+
238+
if (memcached_behavior_set(memc_sess->memc_sess, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, (uint64_t) MEMC_G(sess_connect_timeout)) == MEMCACHED_FAILURE) {
239+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to set memcached connection timeout");
240+
return FAILURE;
241+
}
237242

238243
/* Allow libmemcached remove failed servers */
239244
if (MEMC_G(sess_remove_failed_enabled)) {

0 commit comments

Comments
 (0)