@@ -1765,6 +1765,7 @@ PHP_METHOD(Memcached, setByKey)
17651765}
17661766/* }}} */
17671767
1768+ #ifdef HAVE_MEMCACHED_TOUCH
17681769/* {{{ Memcached::touch(string key, [, int expiration ])
17691770 Sets a new expiration for the given key */
17701771PHP_METHOD (Memcached , touch )
@@ -1780,6 +1781,8 @@ PHP_METHOD(Memcached, touchByKey)
17801781 php_memc_store_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , MEMC_OP_TOUCH , 1 );
17811782}
17821783/* }}} */
1784+ #endif
1785+
17831786
17841787/* {{{ Memcached::setMulti(array items [, int expiration ])
17851788 Sets the keys/values specified in the items array */
@@ -2319,7 +2322,17 @@ PHP_METHOD(Memcached, addServer)
23192322 MEMC_METHOD_FETCH_OBJECT ;
23202323 s_memc_set_status (intern , MEMCACHED_SUCCESS , 0 );
23212324
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
23222334 status = memcached_server_add_with_weight (intern -> memc , ZSTR_VAL (host ), port , weight );
2335+ #endif
23232336
23242337 if (s_memc_status_handle_result_code (intern , status ) == FAILURE ) {
23252338 RETURN_FALSE ;
@@ -2515,6 +2528,7 @@ PHP_METHOD(Memcached, flushBuffers)
25152528}
25162529/* }}} */
25172530
2531+ #ifdef HAVE_LIBMEMCACHED_CHECK_CONFIGURATION
25182532/* {{{ Memcached::getLastErrorMessage()
25192533 Returns the last error message that occurred */
25202534PHP_METHOD (Memcached , getLastErrorMessage )
@@ -2562,6 +2576,7 @@ PHP_METHOD(Memcached, getLastErrorErrno)
25622576 RETURN_LONG (memcached_last_error_errno (intern -> memc ));
25632577}
25642578/* }}} */
2579+ #endif
25652580
25662581/* {{{ Memcached::getLastDisconnectedServer()
25672582 Returns the last disconnected server
@@ -2801,7 +2816,11 @@ static PHP_METHOD(Memcached, getOption)
28012816
28022817 result = memcached_callback_get (intern -> memc , MEMCACHED_CALLBACK_PREFIX_KEY , & retval );
28032818 if (retval == MEMCACHED_SUCCESS && result ) {
2819+ #if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX == 0x00049000
2820+ RETURN_STRINGL (result , strlen (result ));
2821+ #else
28042822 RETURN_STRING (result );
2823+ #endif
28052824 } else {
28062825 RETURN_EMPTY_STRING ();
28072826 }
@@ -2866,11 +2885,23 @@ int php_memc_set_option(php_memc_object_t *intern, long option, zval *value)
28662885 {
28672886 zend_string * str ;
28682887 char * key ;
2888+ #if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX == 0x00049000
2889+ char tmp [MEMCACHED_PREFIX_KEY_MAX_SIZE - 1 ];
2890+ #endif
28692891 str = zval_get_string (value );
28702892 if (ZSTR_LEN (str ) == 0 ) {
28712893 key = NULL ;
28722894 } 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
28732903 key = ZSTR_VAL (str );
2904+ #endif
28742905 }
28752906 if (memcached_callback_set (intern -> memc , MEMCACHED_CALLBACK_PREFIX_KEY , key ) == MEMCACHED_BAD_KEY_PROVIDED ) {
28762907 zend_string_release (str );
@@ -2899,9 +2930,14 @@ int php_memc_set_option(php_memc_object_t *intern, long option, zval *value)
28992930 * (non-weighted) case. We have to clean up ourselves.
29002931 */
29012932 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
29052941 }
29062942 break ;
29072943
@@ -3984,10 +4020,10 @@ static zend_function_entry memcached_class_methods[] = {
39844020
39854021 MEMC_ME (set , arginfo_set )
39864022 MEMC_ME (setByKey , arginfo_setByKey )
3987-
4023+ #ifdef HAVE_MEMCACHED_TOUCH
39884024 MEMC_ME (touch , arginfo_touch )
39894025 MEMC_ME (touchByKey , arginfo_touchByKey )
3990-
4026+ #endif
39914027 MEMC_ME (setMulti , arginfo_setMulti )
39924028 MEMC_ME (setMultiByKey , arginfo_setMultiByKey )
39934029
@@ -4019,10 +4055,11 @@ static zend_function_entry memcached_class_methods[] = {
40194055 MEMC_ME (quit , arginfo_quit )
40204056 MEMC_ME (flushBuffers , arginfo_flushBuffers )
40214057
4058+ #if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX >= 0x00049000
40224059 MEMC_ME (getLastErrorMessage , arginfo_getLastErrorMessage )
40234060 MEMC_ME (getLastErrorCode , arginfo_getLastErrorCode )
40244061 MEMC_ME (getLastErrorErrno , arginfo_getLastErrorErrno )
4025-
4062+ #endif
40264063 MEMC_ME (getLastDisconnectedServer , arginfo_getLastDisconnectedServer )
40274064
40284065 MEMC_ME (getStats , arginfo_getStats )
@@ -4215,8 +4252,9 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
42154252 REGISTER_MEMC_CLASS_CONST_LONG (OPT_DISTRIBUTION , MEMCACHED_BEHAVIOR_DISTRIBUTION );
42164253 REGISTER_MEMC_CLASS_CONST_LONG (DISTRIBUTION_MODULA , MEMCACHED_DISTRIBUTION_MODULA );
42174254 REGISTER_MEMC_CLASS_CONST_LONG (DISTRIBUTION_CONSISTENT , MEMCACHED_DISTRIBUTION_CONSISTENT );
4255+ #if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX >= 0x00049000
42184256 REGISTER_MEMC_CLASS_CONST_LONG (DISTRIBUTION_VIRTUAL_BUCKET , MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET );
4219-
4257+ #endif
42204258 REGISTER_MEMC_CLASS_CONST_LONG (OPT_LIBKETAMA_COMPATIBLE , MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED );
42214259 REGISTER_MEMC_CLASS_CONST_LONG (OPT_LIBKETAMA_HASH , MEMCACHED_BEHAVIOR_KETAMA_HASH );
42224260 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)
42424280 REGISTER_MEMC_CLASS_CONST_LONG (OPT_SORT_HOSTS , MEMCACHED_BEHAVIOR_SORT_HOSTS );
42434281 REGISTER_MEMC_CLASS_CONST_LONG (OPT_VERIFY_KEY , MEMCACHED_BEHAVIOR_VERIFY_KEY );
42444282 REGISTER_MEMC_CLASS_CONST_LONG (OPT_USE_UDP , MEMCACHED_BEHAVIOR_USE_UDP );
4283+ #if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX >= 0x00037000
42454284 REGISTER_MEMC_CLASS_CONST_LONG (OPT_NUMBER_OF_REPLICAS , MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS );
42464285 REGISTER_MEMC_CLASS_CONST_LONG (OPT_RANDOMIZE_REPLICA_READ , MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ );
4286+ #endif
4287+ #ifdef HAVE_MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS
42474288 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
42494291 REGISTER_MEMC_CLASS_CONST_LONG (OPT_SERVER_TIMEOUT_LIMIT , MEMCACHED_BEHAVIOR_SERVER_TIMEOUT_LIMIT );
42504292#endif
42514293
0 commit comments