@@ -1765,6 +1765,7 @@ PHP_METHOD(Memcached, setByKey)
1765
1765
}
1766
1766
/* }}} */
1767
1767
1768
+ #ifdef HAVE_MEMCACHED_TOUCH
1768
1769
/* {{{ Memcached::touch(string key, [, int expiration ])
1769
1770
Sets a new expiration for the given key */
1770
1771
PHP_METHOD (Memcached , touch )
@@ -1780,6 +1781,8 @@ PHP_METHOD(Memcached, touchByKey)
1780
1781
php_memc_store_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , MEMC_OP_TOUCH , 1 );
1781
1782
}
1782
1783
/* }}} */
1784
+ #endif
1785
+
1783
1786
1784
1787
/* {{{ Memcached::setMulti(array items [, int expiration ])
1785
1788
Sets the keys/values specified in the items array */
@@ -2319,7 +2322,17 @@ PHP_METHOD(Memcached, addServer)
2319
2322
MEMC_METHOD_FETCH_OBJECT ;
2320
2323
s_memc_set_status (intern , MEMCACHED_SUCCESS , 0 );
2321
2324
2325
+ #if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX < 0x01000002
2326
+ if (ZSTR_VAL (host )[0 ] == '/' ) { /* unix domain socket */
2327
+ status = memcached_server_add_unix_socket_with_weight (intern -> memc , ZSTR_VAL (host ), weight );
2328
+ } else if (memcached_behavior_get (intern -> memc , MEMCACHED_BEHAVIOR_USE_UDP )) {
2329
+ status = memcached_server_add_udp_with_weight (intern -> memc , ZSTR_VAL (host ), port , weight );
2330
+ } else {
2331
+ status = memcached_server_add_with_weight (intern -> memc , ZSTR_VAL (host ), port , weight );
2332
+ }
2333
+ #else
2322
2334
status = memcached_server_add_with_weight (intern -> memc , ZSTR_VAL (host ), port , weight );
2335
+ #endif
2323
2336
2324
2337
if (s_memc_status_handle_result_code (intern , status ) == FAILURE ) {
2325
2338
RETURN_FALSE ;
@@ -2515,6 +2528,7 @@ PHP_METHOD(Memcached, flushBuffers)
2515
2528
}
2516
2529
/* }}} */
2517
2530
2531
+ #ifdef HAVE_LIBMEMCACHED_CHECK_CONFIGURATION
2518
2532
/* {{{ Memcached::getLastErrorMessage()
2519
2533
Returns the last error message that occurred */
2520
2534
PHP_METHOD (Memcached , getLastErrorMessage )
@@ -2562,6 +2576,7 @@ PHP_METHOD(Memcached, getLastErrorErrno)
2562
2576
RETURN_LONG (memcached_last_error_errno (intern -> memc ));
2563
2577
}
2564
2578
/* }}} */
2579
+ #endif
2565
2580
2566
2581
/* {{{ Memcached::getLastDisconnectedServer()
2567
2582
Returns the last disconnected server
@@ -2801,7 +2816,11 @@ static PHP_METHOD(Memcached, getOption)
2801
2816
2802
2817
result = memcached_callback_get (intern -> memc , MEMCACHED_CALLBACK_PREFIX_KEY , & retval );
2803
2818
if (retval == MEMCACHED_SUCCESS && result ) {
2819
+ #if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX == 0x00049000
2820
+ RETURN_STRINGL (result , strlen (result ));
2821
+ #else
2804
2822
RETURN_STRING (result );
2823
+ #endif
2805
2824
} else {
2806
2825
RETURN_EMPTY_STRING ();
2807
2826
}
@@ -2866,11 +2885,23 @@ int php_memc_set_option(php_memc_object_t *intern, long option, zval *value)
2866
2885
{
2867
2886
zend_string * str ;
2868
2887
char * key ;
2888
+ #if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX == 0x00049000
2889
+ char tmp [MEMCACHED_PREFIX_KEY_MAX_SIZE - 1 ];
2890
+ #endif
2869
2891
str = zval_get_string (value );
2870
2892
if (ZSTR_LEN (str ) == 0 ) {
2871
2893
key = NULL ;
2872
2894
} else {
2895
+ /*
2896
+ work-around a bug in libmemcached in version 0.49 that truncates the trailing
2897
+ character of the key prefix, to avoid the issue we pad it with a '0'
2898
+ */
2899
+ #if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX == 0x00049000
2900
+ snprintf (tmp , sizeof (tmp ), "%s0" , ZSTR_VAL (str ));
2901
+ key = tmp ;
2902
+ #else
2873
2903
key = ZSTR_VAL (str );
2904
+ #endif
2874
2905
}
2875
2906
if (memcached_callback_set (intern -> memc , MEMCACHED_CALLBACK_PREFIX_KEY , key ) == MEMCACHED_BAD_KEY_PROVIDED ) {
2876
2907
zend_string_release (str );
@@ -2899,9 +2930,14 @@ int php_memc_set_option(php_memc_object_t *intern, long option, zval *value)
2899
2930
* (non-weighted) case. We have to clean up ourselves.
2900
2931
*/
2901
2932
if (!lval ) {
2902
- (void )memcached_behavior_set_key_hash (intern -> memc , MEMCACHED_HASH_DEFAULT );
2903
- (void )memcached_behavior_set_distribution_hash (intern -> memc , MEMCACHED_HASH_DEFAULT );
2904
- (void )memcached_behavior_set_distribution (intern -> memc , MEMCACHED_DISTRIBUTION_MODULA );
2933
+ #if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX > 0x00037000
2934
+ (void )memcached_behavior_set_key_hash (intern -> memc , MEMCACHED_HASH_DEFAULT );
2935
+ (void )memcached_behavior_set_distribution_hash (intern -> memc , MEMCACHED_HASH_DEFAULT );
2936
+ (void )memcached_behavior_set_distribution (intern -> memc , MEMCACHED_DISTRIBUTION_MODULA );
2937
+ #else
2938
+ intern -> memc -> hash = 0 ;
2939
+ intern -> memc -> distribution = 0 ;
2940
+ #endif
2905
2941
}
2906
2942
break ;
2907
2943
@@ -3984,10 +4020,10 @@ static zend_function_entry memcached_class_methods[] = {
3984
4020
3985
4021
MEMC_ME (set , arginfo_set )
3986
4022
MEMC_ME (setByKey , arginfo_setByKey )
3987
-
4023
+ #ifdef HAVE_MEMCACHED_TOUCH
3988
4024
MEMC_ME (touch , arginfo_touch )
3989
4025
MEMC_ME (touchByKey , arginfo_touchByKey )
3990
-
4026
+ #endif
3991
4027
MEMC_ME (setMulti , arginfo_setMulti )
3992
4028
MEMC_ME (setMultiByKey , arginfo_setMultiByKey )
3993
4029
@@ -4019,10 +4055,11 @@ static zend_function_entry memcached_class_methods[] = {
4019
4055
MEMC_ME (quit , arginfo_quit )
4020
4056
MEMC_ME (flushBuffers , arginfo_flushBuffers )
4021
4057
4058
+ #if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX >= 0x00049000
4022
4059
MEMC_ME (getLastErrorMessage , arginfo_getLastErrorMessage )
4023
4060
MEMC_ME (getLastErrorCode , arginfo_getLastErrorCode )
4024
4061
MEMC_ME (getLastErrorErrno , arginfo_getLastErrorErrno )
4025
-
4062
+ #endif
4026
4063
MEMC_ME (getLastDisconnectedServer , arginfo_getLastDisconnectedServer )
4027
4064
4028
4065
MEMC_ME (getStats , arginfo_getStats )
@@ -4215,8 +4252,9 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
4215
4252
REGISTER_MEMC_CLASS_CONST_LONG (OPT_DISTRIBUTION , MEMCACHED_BEHAVIOR_DISTRIBUTION );
4216
4253
REGISTER_MEMC_CLASS_CONST_LONG (DISTRIBUTION_MODULA , MEMCACHED_DISTRIBUTION_MODULA );
4217
4254
REGISTER_MEMC_CLASS_CONST_LONG (DISTRIBUTION_CONSISTENT , MEMCACHED_DISTRIBUTION_CONSISTENT );
4255
+ #if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX >= 0x00049000
4218
4256
REGISTER_MEMC_CLASS_CONST_LONG (DISTRIBUTION_VIRTUAL_BUCKET , MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET );
4219
-
4257
+ #endif
4220
4258
REGISTER_MEMC_CLASS_CONST_LONG (OPT_LIBKETAMA_COMPATIBLE , MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED );
4221
4259
REGISTER_MEMC_CLASS_CONST_LONG (OPT_LIBKETAMA_HASH , MEMCACHED_BEHAVIOR_KETAMA_HASH );
4222
4260
REGISTER_MEMC_CLASS_CONST_LONG (OPT_TCP_KEEPALIVE , MEMCACHED_BEHAVIOR_TCP_KEEPALIVE );
@@ -4242,10 +4280,14 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
4242
4280
REGISTER_MEMC_CLASS_CONST_LONG (OPT_SORT_HOSTS , MEMCACHED_BEHAVIOR_SORT_HOSTS );
4243
4281
REGISTER_MEMC_CLASS_CONST_LONG (OPT_VERIFY_KEY , MEMCACHED_BEHAVIOR_VERIFY_KEY );
4244
4282
REGISTER_MEMC_CLASS_CONST_LONG (OPT_USE_UDP , MEMCACHED_BEHAVIOR_USE_UDP );
4283
+ #if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX >= 0x00037000
4245
4284
REGISTER_MEMC_CLASS_CONST_LONG (OPT_NUMBER_OF_REPLICAS , MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS );
4246
4285
REGISTER_MEMC_CLASS_CONST_LONG (OPT_RANDOMIZE_REPLICA_READ , MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ );
4286
+ #endif
4287
+ #ifdef HAVE_MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS
4247
4288
REGISTER_MEMC_CLASS_CONST_LONG (OPT_REMOVE_FAILED_SERVERS , MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS );
4248
- #if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX >= 0x01000018
4289
+ #endif
4290
+ #ifdef HAVE_MEMCACHED_BEHAVIOR_SERVER_TIMEOUT_LIMIT
4249
4291
REGISTER_MEMC_CLASS_CONST_LONG (OPT_SERVER_TIMEOUT_LIMIT , MEMCACHED_BEHAVIOR_SERVER_TIMEOUT_LIMIT );
4250
4292
#endif
4251
4293
0 commit comments