@@ -341,6 +341,11 @@ PHP_INI_BEGIN()
341341 MEMC_INI_ENTRY ("compression_threshold" , "2000" , OnUpdateLong , compression_threshold )
342342 MEMC_INI_ENTRY ("serializer" , SERIALIZER_DEFAULT_NAME , OnUpdateSerializer , serializer_name )
343343 MEMC_INI_ENTRY ("store_retry_count" , "2" , OnUpdateLong , store_retry_count )
344+
345+ MEMC_INI_ENTRY ("default_consistent_hash" , "0" , OnUpdateBool , default_behavior .consistent_hash_enabled )
346+ MEMC_INI_ENTRY ("default_binary_protocol" , "0" , OnUpdateBool , default_behavior .binary_protocol_enabled )
347+ MEMC_INI_ENTRY ("default_connect_timeout" , "0" , OnUpdateLongGEZero , default_behavior .connect_timeout )
348+
344349PHP_INI_END ()
345350/* }}} */
346351
@@ -1190,7 +1195,8 @@ static PHP_METHOD(Memcached, __construct)
11901195 }
11911196
11921197 if (!intern -> memc ) {
1193- // TODO: handle allocation fail
1198+ php_error_docref (NULL , E_ERROR , "Failed to allocate memory for memcached structure" );
1199+ /* never reached */
11941200 }
11951201
11961202 memc_user_data = pecalloc (1 , sizeof (* memc_user_data ), is_persistent );
@@ -1203,6 +1209,38 @@ static PHP_METHOD(Memcached, __construct)
12031209
12041210 memcached_set_user_data (intern -> memc , memc_user_data );
12051211
1212+ /* Set default behaviors */
1213+ {
1214+ #ifdef mikko_0
1215+ fprintf (stderr , "consistent_hash_enabled=%d binary_protocol_enabled=%d connect_timeout=%ld\n" ,
1216+ MEMC_G (default_behavior .consistent_hash_enabled ), MEMC_G (default_behavior .binary_protocol_enabled ), MEMC_G (default_behavior .connect_timeout ));
1217+ #endif
1218+
1219+ memcached_return rc ;
1220+
1221+ if (MEMC_G (default_behavior .consistent_hash_enabled )) {
1222+
1223+ rc = memcached_behavior_set (intern -> memc , MEMCACHED_BEHAVIOR_DISTRIBUTION , MEMCACHED_DISTRIBUTION_CONSISTENT );
1224+ if (rc != MEMCACHED_SUCCESS ) {
1225+ php_error_docref (NULL , E_WARNING , "Failed to turn on consistent hash: %s" , memcached_strerror (intern -> memc , rc ));
1226+ }
1227+ }
1228+
1229+ if (MEMC_G (default_behavior .binary_protocol_enabled )) {
1230+ rc = memcached_behavior_set (intern -> memc , MEMCACHED_BEHAVIOR_BINARY_PROTOCOL , 1 );
1231+ if (rc != MEMCACHED_SUCCESS ) {
1232+ php_error_docref (NULL , E_WARNING , "Failed to turn on binary protocol: %s" , memcached_strerror (intern -> memc , rc ));
1233+ }
1234+ }
1235+
1236+ if (MEMC_G (default_behavior .connect_timeout )) {
1237+ rc = memcached_behavior_set (intern -> memc , MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT , MEMC_G (default_behavior .connect_timeout ));
1238+ if (rc != MEMCACHED_SUCCESS ) {
1239+ php_error_docref (NULL , E_WARNING , "Failed to set connect timeout: %s" , memcached_strerror (intern -> memc , rc ));
1240+ }
1241+ }
1242+ }
1243+
12061244 if (fci .size ) {
12071245 if (!s_invoke_new_instance_cb (getThis (), & fci , & fci_cache , persistent_id ) || EG (exception )) {
12081246 /* error calling or exception thrown from callback */
@@ -2263,7 +2301,7 @@ PHP_METHOD(Memcached, addServer)
22632301 }
22642302
22652303 MEMC_METHOD_FETCH_OBJECT ;
2266- intern -> rescode = MEMCACHED_SUCCESS ;
2304+ s_memc_set_status ( intern , MEMCACHED_SUCCESS , 0 ) ;
22672305
22682306#if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX < 0x01000002
22692307 if (host -> val [0 ] == '/' ) { /* unix domain socket */
@@ -2712,7 +2750,7 @@ static PHP_METHOD(Memcached, flush)
27122750 }
27132751
27142752 MEMC_METHOD_FETCH_OBJECT ;
2715- intern -> rescode = MEMCACHED_SUCCESS ;
2753+ s_memc_set_status ( intern , MEMCACHED_SUCCESS , 0 ) ;
27162754
27172755 status = memcached_flush (intern -> memc , delay );
27182756 if (s_memc_status_handle_result_code (intern , status ) == FAILURE ) {
@@ -4100,6 +4138,11 @@ PHP_GINIT_FUNCTION(php_memcached)
41004138
41014139 php_memcached_globals -> memc .sasl_initialised = 0 ;
41024140 php_memcached_globals -> no_effect = 0 ;
4141+
4142+ /* Defaults for certain options */
4143+ php_memcached_globals -> memc .default_behavior .consistent_hash_enabled = 0 ;
4144+ php_memcached_globals -> memc .default_behavior .binary_protocol_enabled = 0 ;
4145+ php_memcached_globals -> memc .default_behavior .connect_timeout = 0 ;
41034146}
41044147
41054148zend_module_entry memcached_module_entry = {
0 commit comments