@@ -323,6 +323,22 @@ PHP_INI_MH(OnUpdateSessionPrefixString)
323
323
return OnUpdateString (entry , new_value , mh_arg1 , mh_arg2 , mh_arg3 , stage );
324
324
}
325
325
326
+ static
327
+ PHP_INI_MH (OnUpdateConsistentHash )
328
+ {
329
+ if (!new_value ) {
330
+ MEMC_SESS_INI (consistent_hash_type ) = MEMCACHED_BEHAVIOR_KETAMA ;
331
+ } else if (!strcmp (ZSTR_VAL (new_value ), "ketama" )) {
332
+ MEMC_SESS_INI (consistent_hash_type ) = MEMCACHED_BEHAVIOR_KETAMA ;
333
+ } else if (!strcmp (ZSTR_VAL (new_value ), "ketama_weighted" )) {
334
+ MEMC_SESS_INI (consistent_hash_type ) = MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED ;
335
+ } else {
336
+ php_error_docref (NULL , E_WARNING , "memcached.sess_consistent_hash_type must be ketama or ketama_weighted" );
337
+ return FAILURE ;
338
+ }
339
+ return OnUpdateString (entry , new_value , mh_arg1 , mh_arg2 , mh_arg3 , stage );
340
+ }
341
+
326
342
#define MEMC_INI_ENTRY (key , default_value , update_fn , gkey ) \
327
343
STD_PHP_INI_ENTRY("memcached."key, default_value, PHP_INI_ALL, update_fn, memc.gkey, zend_php_memcached_globals, php_memcached_globals)
328
344
@@ -357,6 +373,7 @@ PHP_INI_BEGIN()
357
373
MEMC_SESSION_INI_BOOL ("binary_protocol" , "1" , OnUpdateBool , binary_protocol_enabled )
358
374
#endif
359
375
MEMC_SESSION_INI_BOOL ("consistent_hash" , "1" , OnUpdateBool , consistent_hash_enabled )
376
+ MEMC_SESSION_INI_ENTRY ("consistent_hash_type" , "ketama" , OnUpdateConsistentHash , consistent_hash_name )
360
377
MEMC_SESSION_INI_ENTRY ("number_of_replicas" , "0" , OnUpdateLongGEZero , number_of_replicas )
361
378
MEMC_SESSION_INI_BOOL ("randomize_replica_read" , "0" , OnUpdateBool , randomize_replica_read_enabled )
362
379
MEMC_SESSION_INI_BOOL ("remove_failed_servers" , "0" , OnUpdateBool , remove_failed_servers_enabled )
@@ -1254,7 +1271,6 @@ static PHP_METHOD(Memcached, __construct)
1254
1271
1255
1272
/* Set default behaviors */
1256
1273
if (MEMC_G (default_behavior .consistent_hash_enabled )) {
1257
-
1258
1274
memcached_return rc = memcached_behavior_set (intern -> memc , MEMCACHED_BEHAVIOR_DISTRIBUTION , MEMCACHED_DISTRIBUTION_CONSISTENT );
1259
1275
if (rc != MEMCACHED_SUCCESS ) {
1260
1276
php_error_docref (NULL , E_WARNING , "Failed to turn on consistent hash: %s" , memcached_strerror (intern -> memc , rc ));
@@ -4263,6 +4279,8 @@ PHP_GINIT_FUNCTION(php_memcached)
4263
4279
php_memcached_globals -> session .lock_expiration = 30 ;
4264
4280
php_memcached_globals -> session .binary_protocol_enabled = 1 ;
4265
4281
php_memcached_globals -> session .consistent_hash_enabled = 1 ;
4282
+ php_memcached_globals -> session .consistent_hash_type = MEMCACHED_BEHAVIOR_KETAMA ;
4283
+ php_memcached_globals -> session .consistent_hash_name = NULL ;
4266
4284
php_memcached_globals -> session .number_of_replicas = 0 ;
4267
4285
php_memcached_globals -> session .server_failure_limit = 1 ;
4268
4286
php_memcached_globals -> session .randomize_replica_read_enabled = 1 ;
0 commit comments