@@ -341,6 +341,11 @@ PHP_INI_BEGIN()
341
341
MEMC_INI_ENTRY ("compression_threshold" , "2000" , OnUpdateLong , compression_threshold )
342
342
MEMC_INI_ENTRY ("serializer" , SERIALIZER_DEFAULT_NAME , OnUpdateSerializer , serializer_name )
343
343
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
+
344
349
PHP_INI_END ()
345
350
/* }}} */
346
351
@@ -1190,7 +1195,8 @@ static PHP_METHOD(Memcached, __construct)
1190
1195
}
1191
1196
1192
1197
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 */
1194
1200
}
1195
1201
1196
1202
memc_user_data = pecalloc (1 , sizeof (* memc_user_data ), is_persistent );
@@ -1203,6 +1209,38 @@ static PHP_METHOD(Memcached, __construct)
1203
1209
1204
1210
memcached_set_user_data (intern -> memc , memc_user_data );
1205
1211
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
+
1206
1244
if (fci .size ) {
1207
1245
if (!s_invoke_new_instance_cb (getThis (), & fci , & fci_cache , persistent_id ) || EG (exception )) {
1208
1246
/* error calling or exception thrown from callback */
@@ -2263,7 +2301,7 @@ PHP_METHOD(Memcached, addServer)
2263
2301
}
2264
2302
2265
2303
MEMC_METHOD_FETCH_OBJECT ;
2266
- intern -> rescode = MEMCACHED_SUCCESS ;
2304
+ s_memc_set_status ( intern , MEMCACHED_SUCCESS , 0 ) ;
2267
2305
2268
2306
#if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX < 0x01000002
2269
2307
if (host -> val [0 ] == '/' ) { /* unix domain socket */
@@ -2712,7 +2750,7 @@ static PHP_METHOD(Memcached, flush)
2712
2750
}
2713
2751
2714
2752
MEMC_METHOD_FETCH_OBJECT ;
2715
- intern -> rescode = MEMCACHED_SUCCESS ;
2753
+ s_memc_set_status ( intern , MEMCACHED_SUCCESS , 0 ) ;
2716
2754
2717
2755
status = memcached_flush (intern -> memc , delay );
2718
2756
if (s_memc_status_handle_result_code (intern , status ) == FAILURE ) {
@@ -4100,6 +4138,11 @@ PHP_GINIT_FUNCTION(php_memcached)
4100
4138
4101
4139
php_memcached_globals -> memc .sasl_initialised = 0 ;
4102
4140
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 ;
4103
4146
}
4104
4147
4105
4148
zend_module_entry memcached_module_entry = {
0 commit comments