From 9e11ffa8e5d5e6b1256dc44b7f043e7114122170 Mon Sep 17 00:00:00 2001 From: Mikko Date: Sat, 16 Jan 2016 21:40:35 +0000 Subject: [PATCH 01/15] Revert the user flags and move into Memcached::getLastUserFlags --- php_memcached.c | 194 +++++++++++++++++++++--------------------- tests/user-flags.phpt | 72 +++++++++++----- 2 files changed, 148 insertions(+), 118 deletions(-) diff --git a/php_memcached.c b/php_memcached.c index a6c338b8..1339f308 100644 --- a/php_memcached.c +++ b/php_memcached.c @@ -58,6 +58,7 @@ #define MEMC_OPT_SERIALIZER -1003 #define MEMC_OPT_COMPRESSION_TYPE -1004 #define MEMC_OPT_STORE_RETRY_COUNT -1005 +#define MEMC_OPT_USER_FLAGS -1006 /**************************************** Custom result codes @@ -153,8 +154,10 @@ typedef struct { zend_bool has_sasl_data; #endif long store_retry_count; + zend_long set_udf_flags; } *obj; + zval last_udf_flags; zend_bool is_persistent; zend_bool is_pristine; int rescode; @@ -466,6 +469,9 @@ static PHP_METHOD(Memcached, __construct) m_obj->compression = 1; m_obj->store_retry_count = MEMC_G(store_retry_count); + m_obj->set_udf_flags = -1; + array_init(&i_obj->last_udf_flags); + i_obj->obj = m_obj; i_obj->is_pristine = 1; @@ -508,7 +514,23 @@ static PHP_METHOD(Memcached, __construct) } /* }}} */ -/* {{{ Memcached::get(string key [, mixed callback [, double &cas_token [, int &udf_flags ] ] ]) +/* {{{ Memcached::getLastUserFlags() + Returns the user flags from last fetch operation */ +PHP_METHOD(Memcached, getLastUserFlags) +{ + MEMC_METHOD_INIT_VARS; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + MEMC_METHOD_FETCH_OBJECT; + RETVAL_ZVAL(&i_obj->last_udf_flags, 1, 0); +} +/* }}} */ + + +/* {{{ Memcached::get(string key [, mixed callback [, double &cas_token ] ]) Returns a value for the given key or false */ PHP_METHOD(Memcached, get) { @@ -516,7 +538,7 @@ PHP_METHOD(Memcached, get) } /* }}} */ -/* {{{ Memcached::getByKey(string server_key, string key [, mixed callback [, double &cas_token [, int &udf_flags ] ] ]) +/* {{{ Memcached::getByKey(string server_key, string key [, mixed callback [, double &cas_token ] ]) Returns a value for key from the server identified by the server key or false */ PHP_METHOD(Memcached, getByKey) { @@ -536,7 +558,6 @@ static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) const char* keys[1] = { NULL }; size_t key_lens[1] = { 0 }; zval *cas_token = NULL; - zval *udf_flags = NULL; uint64_t orig_cas_flag; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; @@ -545,13 +566,11 @@ static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) MEMC_METHOD_INIT_VARS; if (by_key) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|f!zz", &server_key, &key, - &fci, &fcc, &cas_token, &udf_flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|f!z", &server_key, &key, &fci, &fcc, &cas_token) == FAILURE) { return; } } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|f!zz", &key, - &fci, &fcc, &cas_token, &udf_flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|f!z", &key, &fci, &fcc, &cas_token) == FAILURE) { return; } } @@ -559,7 +578,9 @@ static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) MEMC_METHOD_FETCH_OBJECT; i_obj->rescode = MEMCACHED_SUCCESS; - if (key->len == 0 || strchr(key->val, ' ')) { + zend_hash_clean(Z_ARRVAL(i_obj->last_udf_flags)); + + if (key->len == 0) { i_obj->rescode = MEMCACHED_BAD_KEY_PROVIDED; RETURN_FROM_GET; } @@ -650,18 +671,13 @@ static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) ZVAL_DOUBLE(cas_token, (double)cas); } - if (udf_flags) { - ZVAL_DEREF(udf_flags); - SEPARATE_ZVAL(udf_flags); - zval_dtor(udf_flags); - ZVAL_LONG(udf_flags, MEMC_VAL_GET_USER_FLAGS(flags)); - } - + /* Parse user flags */ + add_assoc_long_ex(&i_obj->last_udf_flags, key->val, key->len, MEMC_VAL_GET_USER_FLAGS(flags)); memcached_result_free(&result); } /* }}} */ -/* {{{ Memcached::getMulti(array keys [, array &cas_tokens [, array &udf_flags ] ]) +/* {{{ Memcached::getMulti(array keys [, array &cas_tokens ]) Returns values for the given keys or false */ PHP_METHOD(Memcached, getMulti) { @@ -669,7 +685,7 @@ PHP_METHOD(Memcached, getMulti) } /* }}} */ -/* {{{ Memcached::getMultiByKey(string server_key, array keys [, array &cas_tokens [, array &udf_flags ] ]) +/* {{{ Memcached::getMultiByKey(string server_key, array keys [, array &cas_tokens ]) Returns values for the given keys from the server identified by the server key or false */ PHP_METHOD(Memcached, getMultiByKey) { @@ -693,7 +709,6 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke uint32_t flags; uint64_t cas = 0; zval *cas_tokens = NULL; - zval *udf_flags = NULL; uint64_t orig_cas_flag = 0; zval value; long get_flags = 0; @@ -704,12 +719,12 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke MEMC_METHOD_INIT_VARS; if (by_key) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sa/|zlz", &server_key, - &keys, &cas_tokens, &get_flags, &udf_flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sa/|zl", &server_key, + &keys, &cas_tokens, &get_flags) == FAILURE) { return; } } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/|zlz", &keys, &cas_tokens, &get_flags, &udf_flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/|zl", &keys, &cas_tokens, &get_flags) == FAILURE) { return; } } @@ -717,6 +732,9 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke MEMC_METHOD_FETCH_OBJECT; i_obj->rescode = MEMCACHED_SUCCESS; + /* clean flags */ + zend_hash_clean(Z_ARRVAL(i_obj->last_udf_flags)); + preserve_order = (get_flags & MEMC_GET_PRESERVE_ORDER); num_keys = zend_hash_num_elements(Z_ARRVAL_P(keys)); mkeys = safe_emalloc(num_keys, sizeof(*mkeys), 0); @@ -801,12 +819,6 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke * Iterate through the result set and create the result array. The flags are * returned as longs. */ - if (udf_flags) { - ZVAL_DEREF(udf_flags); - SEPARATE_ZVAL(udf_flags); - zval_dtor(udf_flags); - array_init(udf_flags); - } memcached_result_create(m_obj->memc, &result); while ((memcached_fetch_result(m_obj->memc, &result, &status)) != NULL) { @@ -851,9 +863,7 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke cas = memcached_result_cas(&result); add_assoc_double_ex(cas_tokens, res_key, res_key_len, (double)cas); } - if (udf_flags) { - add_assoc_long_ex(udf_flags, res_key, res_key_len, MEMC_VAL_GET_USER_FLAGS(flags)); - } + add_assoc_long_ex(&i_obj->last_udf_flags, res_key, res_key_len, MEMC_VAL_GET_USER_FLAGS(flags)); } memcached_result_free(&result); @@ -866,12 +876,7 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke zval_dtor(cas_tokens); ZVAL_NULL(cas_tokens); } - if (udf_flags) { - ZVAL_DEREF(udf_flags); - SEPARATE_ZVAL(udf_flags); - zval_dtor(udf_flags); - ZVAL_NULL(udf_flags); - } + zend_hash_clean(Z_ARRVAL(i_obj->last_udf_flags)); zval_dtor(return_value); RETURN_FALSE; } @@ -1136,7 +1141,7 @@ PHP_METHOD(Memcached, fetchAll) } /* }}} */ -/* {{{ Memcached::set(string key, mixed value [, int expiration [, int udf_flags ] ]) +/* {{{ Memcached::set(string key, mixed value [, int expiration ]) Sets the value for the given key */ PHP_METHOD(Memcached, set) { @@ -1144,7 +1149,7 @@ PHP_METHOD(Memcached, set) } /* }}} */ -/* {{{ Memcached::setByKey(string server_key, string key, mixed value [, int expiration [, int udf_flags ] ]) +/* {{{ Memcached::setByKey(string server_key, string key, mixed value [, int expiration ]) Sets the value for the given key on the server identified by the server key */ PHP_METHOD(Memcached, setByKey) { @@ -1171,7 +1176,7 @@ PHP_METHOD(Memcached, touchByKey) #endif -/* {{{ Memcached::setMulti(array items [, int expiration [, int udf_flags ] ]) +/* {{{ Memcached::setMulti(array items [, int expiration ]) Sets the keys/values specified in the items array */ PHP_METHOD(Memcached, setMulti) { @@ -1179,7 +1184,7 @@ PHP_METHOD(Memcached, setMulti) } /* }}} */ -/* {{{ Memcached::setMultiByKey(string server_key, array items [, int expiration [, int udf_flags ] ]) +/* {{{ Memcached::setMultiByKey(string server_key, array items [, int expiration ]) Sets the keys/values specified in the items array on the server identified by the given server key */ PHP_METHOD(Memcached, setMultiByKey) { @@ -1218,7 +1223,6 @@ static void php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke zval *entries; zend_string *server_key = NULL; time_t expiration = 0; - long udf_flags = 0; zval *entry; zend_string *skey, *str_key = NULL; ulong num_key; @@ -1233,11 +1237,11 @@ static void php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke if (by_key) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sa|ll", &server_key, - &entries, &expiration, &udf_flags) == FAILURE) { + &entries, &expiration) == FAILURE) { return; } } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|ll", &entries, &expiration, &udf_flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|ll", &entries, &expiration) == FAILURE) { return; } } @@ -1245,16 +1249,6 @@ static void php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke MEMC_METHOD_FETCH_OBJECT; i_obj->rescode = MEMCACHED_SUCCESS; - /* - * php_memcached uses 16 bits internally to store type, compression and serialization info. - * We use 16 upper bits to store user defined flags. - */ - if (udf_flags > 0) { - if ((uint32_t) udf_flags > MEMC_VAL_USER_FLAGS_MAX) { - php_error_docref(NULL, E_WARNING, "udf_flags will be limited to %u", MEMC_VAL_USER_FLAGS_MAX); - } - } - ZEND_HASH_FOREACH_KEY_VAL (Z_ARRVAL_P(entries), num_key, skey, entry) { if (skey) { str_key = skey; @@ -1274,8 +1268,8 @@ static void php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke MEMC_VAL_SET_FLAG(flags, MEMC_VAL_COMPRESSED); } - if (udf_flags > 0) { - MEMC_VAL_SET_USER_FLAGS(flags, ((uint32_t) udf_flags)); + if (m_obj->set_udf_flags >= 0) { + MEMC_VAL_SET_USER_FLAGS(flags, ((uint32_t) m_obj->set_udf_flags)); } payload = php_memc_zval_to_payload(entry, &payload_len, &flags, m_obj->serializer, m_obj->compression_type); @@ -1312,7 +1306,7 @@ static void php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke } /* }}} */ -/* {{{ Memcached::add(string key, mixed value [, int expiration [, int udf_flags ] ]) +/* {{{ Memcached::add(string key, mixed value [, int expiration ]) Sets the value for the given key, failing if the key already exists */ PHP_METHOD(Memcached, add) { @@ -1320,7 +1314,7 @@ PHP_METHOD(Memcached, add) } /* }}} */ -/* {{{ Memcached::addByKey(string server_key, string key, mixed value [, int expiration [, int udf_flags ] ]) +/* {{{ Memcached::addByKey(string server_key, string key, mixed value [, int expiration ]) Sets the value for the given key on the server identified by the sever key, failing if the key already exists */ PHP_METHOD(Memcached, addByKey) { @@ -1360,7 +1354,7 @@ PHP_METHOD(Memcached, prependByKey) } /* }}} */ -/* {{{ Memcached::replace(string key, mixed value [, int expiration [, int udf_flags ] ]) +/* {{{ Memcached::replace(string key, mixed value [, int expiration ]) Replaces the value for the given key, failing if the key doesn't exist */ PHP_METHOD(Memcached, replace) { @@ -1368,7 +1362,7 @@ PHP_METHOD(Memcached, replace) } /* }}} */ -/* {{{ Memcached::replaceByKey(string server_key, string key, mixed value [, int expiration [, int udf_flags ] ]) +/* {{{ Memcached::replaceByKey(string server_key, string key, mixed value [, int expiration ]) Replaces the value for the given key on the server identified by the server key, failing if the key doesn't exist */ PHP_METHOD(Memcached, replaceByKey) { @@ -1385,7 +1379,6 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool zval s_zvalue; zval *value; long expiration = 0; - long udf_flags = 0; char *payload = NULL; size_t payload_len; uint32_t flags = 0; @@ -1405,7 +1398,7 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool return; } } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSz|ll", &server_key, &key, &value, &expiration, &udf_flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSz|l", &server_key, &key, &value, &expiration) == FAILURE) { return; } } @@ -1421,7 +1414,7 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool return; } } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|ll", &key, &value, &expiration, &udf_flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|l", &key, &value, &expiration) == FAILURE) { return; } } @@ -1430,7 +1423,7 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool MEMC_METHOD_FETCH_OBJECT; i_obj->rescode = MEMCACHED_SUCCESS; - if (key->len == 0 || strchr(key->val, ' ')) { + if (key->len == 0) { i_obj->rescode = MEMCACHED_BAD_KEY_PROVIDED; RETURN_FALSE; } @@ -1452,11 +1445,8 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool * php_memcached uses 16 bits internally to store type, compression and serialization info. * We use 16 upper bits to store user defined flags. */ - if (udf_flags > 0) { - if ((uint32_t) udf_flags > MEMC_VAL_USER_FLAGS_MAX) { - php_error_docref(NULL, E_WARNING, "udf_flags will be limited to %u", MEMC_VAL_USER_FLAGS_MAX); - } - MEMC_VAL_SET_USER_FLAGS(flags, ((uint32_t) udf_flags)); + if (m_obj->set_udf_flags >= 0) { + MEMC_VAL_SET_USER_FLAGS(flags, ((uint32_t) m_obj->set_udf_flags)); } if (op == MEMC_OP_TOUCH) { @@ -1557,7 +1547,6 @@ static void php_memc_cas_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) zend_string *server_key = NULL; zval *value; time_t expiration = 0; - long udf_flags = 0; char *payload; size_t payload_len; uint32_t flags = 0; @@ -1566,12 +1555,12 @@ static void php_memc_cas_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) if (by_key) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "dSSz|ll", &cas_d, &server_key, &key, - &value, &expiration, &udf_flags) == FAILURE) { + &value, &expiration) == FAILURE) { return; } } else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "dSz|ll", &cas_d, &key, &value, - &expiration, &udf_flags) == FAILURE) { + &expiration) == FAILURE) { return; } } @@ -1579,7 +1568,7 @@ static void php_memc_cas_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) MEMC_METHOD_FETCH_OBJECT; i_obj->rescode = MEMCACHED_SUCCESS; - if (key->len == 0 || strchr(key->val, ' ')) { + if (key->len == 0) { i_obj->rescode = MEMCACHED_BAD_KEY_PROVIDED; RETURN_FALSE; } @@ -1594,11 +1583,8 @@ static void php_memc_cas_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) * php_memcached uses 16 bits internally to store type, compression and serialization info. * We use 16 upper bits to store user defined flags. */ - if (udf_flags > 0) { - if ((uint32_t) udf_flags > MEMC_VAL_USER_FLAGS_MAX) { - php_error_docref(NULL, E_WARNING, "udf_flags will be limited to %u", MEMC_VAL_USER_FLAGS_MAX); - } - MEMC_VAL_SET_USER_FLAGS(flags, ((uint32_t) udf_flags)); + if (m_obj->set_udf_flags > 0) { + MEMC_VAL_SET_USER_FLAGS(flags, ((uint32_t) m_obj->set_udf_flags)); } payload = php_memc_zval_to_payload(value, &payload_len, &flags, m_obj->serializer, m_obj->compression_type); @@ -1621,7 +1607,7 @@ static void php_memc_cas_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) } /* }}} */ -/* {{{ Memcached::cas(double cas_token, string key, mixed value [, int expiration [, int udf_flags ] ]) +/* {{{ Memcached::cas(double cas_token, string key, mixed value [, int expiration ]) Sets the value for the given key, failing if the cas_token doesn't match the one in memcache */ PHP_METHOD(Memcached, cas) { @@ -1629,7 +1615,7 @@ PHP_METHOD(Memcached, cas) } /* }}} */ -/* {{{ Memcached::casByKey(double cas_token, string server_key, string key, mixed value [, int expiration [, int udf_flags ] ]) +/* {{{ Memcached::casByKey(double cas_token, string server_key, string key, mixed value [, int expiration ]) Sets the value for the given key on the server identified by the server_key, failing if the cas_token doesn't match the one in memcache */ PHP_METHOD(Memcached, casByKey) { @@ -2344,6 +2330,10 @@ static PHP_METHOD(Memcached, getOption) RETURN_LONG((long)m_obj->serializer); break; + case MEMC_OPT_USER_FLAGS: + RETURN_LONG(m_obj->set_udf_flags); + break; + case MEMC_OPT_STORE_RETRY_COUNT: RETURN_LONG((long)m_obj->store_retry_count); break; @@ -2481,6 +2471,21 @@ static int php_memc_set_option(php_memc_t *i_obj, long option, zval *value) break; } + case MEMC_OPT_USER_FLAGS: + convert_to_long(value); + + if (Z_LVAL_P(value) < 0) { + m_obj->set_udf_flags = -1; + return 1; + } + + if (Z_LVAL_P(value) > MEMC_VAL_USER_FLAGS_MAX) { + php_error_docref(NULL, E_WARNING, "MEMC_OPT_USER_FLAGS must be < %u", MEMC_VAL_USER_FLAGS_MAX); + return 0; + } + m_obj->set_udf_flags = Z_LVAL_P(value); + break; + case MEMC_OPT_STORE_RETRY_COUNT: convert_to_long(value); m_obj->store_retry_count = Z_LVAL_P(value); @@ -2805,23 +2810,23 @@ static void php_memc_destroy(struct memc_obj *m_obj, zend_bool persistent) if (m_obj->memc) { memcached_free(m_obj->memc); } - pefree(m_obj, persistent); } static void php_memc_free_storage(zend_object *obj) { php_memc_t *i_obj = php_memc_fetch_object(obj); - + if (i_obj->obj && !i_obj->is_persistent) { php_memc_destroy(i_obj->obj, 0); } + zval_ptr_dtor(&i_obj->last_udf_flags); zend_object_std_dtor(&i_obj->zo); i_obj->obj = NULL; } -zend_object *php_memc_new(zend_class_entry *ce) +static zend_object *php_memc_new(zend_class_entry *ce) { php_memc_t *i_obj = ecalloc(1, sizeof(php_memc_t) + zend_object_properties_size(ce)); @@ -3514,7 +3519,7 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i fci->param_count = 4; result = zend_call_function(fci, fcc); - + ZVAL_DUP(value, Z_REFVAL(z_val)); expiration = Z_REFVAL(z_expiration); if (result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { @@ -3552,7 +3557,7 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i ZVAL_NULL(value); } - if (&retval) { + if (!Z_ISUNDEF(retval)) { zval_ptr_dtor(&retval); } @@ -3712,7 +3717,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_get, 0, 0, 1) ZEND_ARG_INFO(0, key) ZEND_ARG_INFO(0, cache_cb) ZEND_ARG_INFO(2, cas_token) - ZEND_ARG_INFO(1, udf_flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_getByKey, 0, 0, 2) @@ -3720,14 +3724,12 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_getByKey, 0, 0, 2) ZEND_ARG_INFO(0, key) ZEND_ARG_INFO(0, cache_cb) ZEND_ARG_INFO(2, cas_token) - ZEND_ARG_INFO(1, udf_flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_getMulti, 0, 0, 1) ZEND_ARG_ARRAY_INFO(0, keys, 0) ZEND_ARG_INFO(2, cas_tokens) ZEND_ARG_INFO(0, flags) - ZEND_ARG_INFO(1, udf_flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_getMultiByKey, 0, 0, 2) @@ -3735,7 +3737,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_getMultiByKey, 0, 0, 2) ZEND_ARG_ARRAY_INFO(0, keys, 0) ZEND_ARG_INFO(2, cas_tokens) ZEND_ARG_INFO(0, flags) - ZEND_ARG_INFO(1, udf_flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_getDelayed, 0, 0, 1) @@ -3761,7 +3762,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_set, 0, 0, 2) ZEND_ARG_INFO(0, key) ZEND_ARG_INFO(0, value) ZEND_ARG_INFO(0, expiration) - ZEND_ARG_INFO(0, udf_flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_setByKey, 0, 0, 3) @@ -3769,7 +3769,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_setByKey, 0, 0, 3) ZEND_ARG_INFO(0, key) ZEND_ARG_INFO(0, value) ZEND_ARG_INFO(0, expiration) - ZEND_ARG_INFO(0, udf_flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_touch, 0, 0, 2) @@ -3786,21 +3785,21 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_setMulti, 0, 0, 1) ZEND_ARG_ARRAY_INFO(0, items, 0) ZEND_ARG_INFO(0, expiration) - ZEND_ARG_INFO(0, udf_flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_setMultiByKey, 0, 0, 2) ZEND_ARG_INFO(0, server_key) ZEND_ARG_ARRAY_INFO(0, items, 0) ZEND_ARG_INFO(0, expiration) - ZEND_ARG_INFO(0, udf_flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_getLastUserFlags, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_add, 0, 0, 2) ZEND_ARG_INFO(0, key) ZEND_ARG_INFO(0, value) ZEND_ARG_INFO(0, expiration) - ZEND_ARG_INFO(0, udf_flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_addByKey, 0, 0, 3) @@ -3808,14 +3807,12 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_addByKey, 0, 0, 3) ZEND_ARG_INFO(0, key) ZEND_ARG_INFO(0, value) ZEND_ARG_INFO(0, expiration) - ZEND_ARG_INFO(0, udf_flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_replace, 0, 0, 2) ZEND_ARG_INFO(0, key) ZEND_ARG_INFO(0, value) ZEND_ARG_INFO(0, expiration) - ZEND_ARG_INFO(0, udf_flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_replaceByKey, 0, 0, 3) @@ -3823,7 +3820,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_replaceByKey, 0, 0, 3) ZEND_ARG_INFO(0, key) ZEND_ARG_INFO(0, value) ZEND_ARG_INFO(0, expiration) - ZEND_ARG_INFO(0, udf_flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_append, 0, 0, 2) @@ -3857,7 +3853,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_cas, 0, 0, 3) ZEND_ARG_INFO(0, key) ZEND_ARG_INFO(0, value) ZEND_ARG_INFO(0, expiration) - ZEND_ARG_INFO(0, udf_flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_casByKey, 0, 0, 4) @@ -3866,7 +3861,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_casByKey, 0, 0, 4) ZEND_ARG_INFO(0, key) ZEND_ARG_INFO(0, value) ZEND_ARG_INFO(0, expiration) - ZEND_ARG_INFO(0, udf_flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_delete, 0, 0, 1) @@ -4029,6 +4023,8 @@ static zend_function_entry memcached_class_methods[] = { MEMC_ME(setMulti, arginfo_setMulti) MEMC_ME(setMultiByKey, arginfo_setMultiByKey) + MEMC_ME(getLastUserFlags, arginfo_getLastUserFlags) + MEMC_ME(cas, arginfo_cas) MEMC_ME(casByKey, arginfo_casByKey) MEMC_ME(add, arginfo_add) @@ -4187,6 +4183,8 @@ static void php_memc_register_constants(INIT_FUNC_ARGS) REGISTER_MEMC_CLASS_CONST_LONG(OPT_COMPRESSION_TYPE, MEMC_OPT_COMPRESSION_TYPE); REGISTER_MEMC_CLASS_CONST_LONG(OPT_PREFIX_KEY, MEMC_OPT_PREFIX_KEY); REGISTER_MEMC_CLASS_CONST_LONG(OPT_SERIALIZER, MEMC_OPT_SERIALIZER); + + REGISTER_MEMC_CLASS_CONST_LONG(OPT_USER_FLAGS, MEMC_OPT_USER_FLAGS); REGISTER_MEMC_CLASS_CONST_LONG(OPT_STORE_RETRY_COUNT, MEMC_OPT_STORE_RETRY_COUNT); /* diff --git a/tests/user-flags.phpt b/tests/user-flags.phpt index 2ed44c9a..137ff1e8 100644 --- a/tests/user-flags.phpt +++ b/tests/user-flags.phpt @@ -22,46 +22,78 @@ define ('FLAG_4', 4); define ('FLAG_32', 32); define ('FLAG_64', 64); define ('FLAG_TOO_LARGE', pow(2, 16)); -$x = 0; include dirname (__FILE__) . '/config.inc'; $m = memc_get_instance (array (Memcached::OPT_BINARY_PROTOCOL => true)); $key = uniqid ('udf_test_'); -echo "stored with flags" . PHP_EOL; +// Set with flags off +$m->set ($key, '1', 10); +$m->get($key); +var_dump($m->getLastUserFlags()); -$m->set ($key, '1', 10, FLAG_1 | FLAG_4 | FLAG_64); -$udf_flags = 0; -$value = $m->get ($key, null, $x, $udf_flags); +// Set flags on +$m->setOption(Memcached::OPT_USER_FLAGS, FLAG_1); +$m->set ($key, '1', 10); +$m->get($key); +check_flags($m->getLastUserFlags()[$key], array(FLAG_1)); -check_flags ($udf_flags, array (FLAG_1, FLAG_4, FLAG_64)); +// Multiple flags +$m->setOption(Memcached::OPT_USER_FLAGS, FLAG_1 | FLAG_2 | FLAG_4); +$m->set ($key, '1', 10); +$m->get($key); +check_flags($m->getLastUserFlags()[$key], array(FLAG_1, FLAG_2, FLAG_4)); -echo "stored without flags" . PHP_EOL; -$m->set ($key, '1'); -$value = $m->get ($key, null, $x, $udf_flags); +// Even more flags +$m->setOption(Memcached::OPT_USER_FLAGS, FLAG_1 | FLAG_2 | FLAG_4 | FLAG_32 | FLAG_64); +$m->set ($key, '1', 10); +$m->get($key); +check_flags($m->getLastUserFlags()[$key], array(FLAG_1, FLAG_2, FLAG_4, FLAG_32, FLAG_64)); -var_dump ($udf_flags == 0); -$m->set ($key, '1', 10, FLAG_TOO_LARGE); +// User flags with get multi +$values = array( + uniqid ('udf_test_multi_') => "first", + uniqid ('udf_test_multi_') => "second", + uniqid ('udf_test_multi_') => "third", +); +$m->setOption(Memcached::OPT_USER_FLAGS, FLAG_2 | FLAG_4); +$m->setMulti($values); +$m->getMulti(array_keys($values)); +$flags = $m->getLastUserFlags(); + +foreach (array_keys($values) as $key) { + check_flags($flags[$key], array(FLAG_2, FLAG_4)); +} + +// User flags with compression on +$m->setOption(Memcached::OPT_USER_FLAGS, FLAG_1 | FLAG_2 | FLAG_4); $m->setOption(Memcached::OPT_COMPRESSION, true); $m->setOption(Memcached::OPT_COMPRESSION_TYPE, Memcached::COMPRESSION_FASTLZ); -$m->set ($key, str_repeat ("abcdef1234567890", 200), 10, FLAG_1 | FLAG_4 | FLAG_64); +$m->set ($key, '1', 10); +$m->get($key); +check_flags($m->getLastUserFlags()[$key], array(FLAG_1, FLAG_2, FLAG_4)); -$udf_flags = 0; -$value_back = $m->get($key, null, null, $udf_flags); -check_flags ($udf_flags, array (FLAG_1, FLAG_4, FLAG_64)); +// Too large flags +$m->setOption(Memcached::OPT_USER_FLAGS, FLAG_TOO_LARGE); echo "DONE TEST\n"; ?> --EXPECTF-- -stored with flags +array(1) { + ["udf_test_%s"]=> + int(0) +} +Flags OK Flags OK -stored without flags -bool(true) - -Warning: Memcached::set(): udf_flags will be limited to 65535 in %s on line %d Flags OK +Flags OK +Flags OK +Flags OK +Flags OK + +Warning: Memcached::setOption(): MEMC_OPT_USER_FLAGS must be < 65535 in %s on line %d DONE TEST \ No newline at end of file From 9d5f3b956a7d0575c748cb2a4526171f63cee058 Mon Sep 17 00:00:00 2001 From: Mikko Date: Sat, 16 Jan 2016 21:53:07 +0000 Subject: [PATCH 02/15] Use cache with travis --- .travis.yml | 4 ++++ .travis/travis.sh | 28 +++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 04f90cec..188bedba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,3 +24,7 @@ before_script: script: - ./.travis/travis.sh script $LIBMEMCACHED_VERSION + +cache: + directories: + - $HOME/cache \ No newline at end of file diff --git a/.travis/travis.sh b/.travis/travis.sh index e6733526..e87a372f 100755 --- a/.travis/travis.sh +++ b/.travis/travis.sh @@ -44,6 +44,12 @@ function validate_package_xml() { function install_libmemcached() { + if test -d "${LIBMEMCACHED_PREFIX}" + then + echo "Using cached libmemcached: ${LIBMEMCACHED_PREFIX}" + return + fi + wget "https://launchpad.net/libmemcached/1.0/${LIBMEMCACHED_VERSION}/+download/libmemcached-${LIBMEMCACHED_VERSION}.tar.gz" -O libmemcached-${LIBMEMCACHED_VERSION}.tar.gz tar xvfz libmemcached-${LIBMEMCACHED_VERSION}.tar.gz @@ -83,17 +89,25 @@ function install_msgpack() { function install_sasl() { - wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz -O memcached-1.4.15.tar.gz - tar xfz memcached-1.4.15.tar.gz + local prefix="${HOME}/cache/memcached" + + if test -f "${prefix}/bin/memcached" + then + echo "Using cached memcached-sasl: ${prefix}/bin/memcached" + return + fi + + wget http://www.memcached.org/files/memcached-1.4.25.tar.gz -O memcached-1.4.25.tar.gz + tar xfz memcached-1.4.25.tar.gz - pushd memcached-1.4.15 - ./configure --enable-sasl --prefix="${HOME}/memcached" + pushd memcached-1.4.25 + ./configure --enable-sasl --prefix="${prefix}" make make install popd sudo apt-get install sasl2-bin - export SASL_CONF_PATH="${HOME}/sasl2" + export SASL_CONF_PATH="${HOME}/cache/sasl2" # Create config path mkdir "${SASL_CONF_PATH}" @@ -109,7 +123,7 @@ EOF echo "test" | /usr/sbin/saslpasswd2 -c memcached -a memcached -f "${SASL_CONF_PATH}/sasldb2" # Run memcached on port 11212 with SASL support - "${HOME}/memcached/bin/memcached" -S -d -p 11212 + "${prefix}/bin/memcached" -S -d -p 11212 } function build_php_memcached() { @@ -192,7 +206,7 @@ fi PHP_MEMCACHED_VERSION=$(php -r '$sxe = simplexml_load_file ("package.xml"); echo (string) $sxe->version->release;') # Libmemcached install dir -LIBMEMCACHED_PREFIX="${HOME}/libmemcached-${LIBMEMCACHED_VERSION}" +LIBMEMCACHED_PREFIX="${HOME}/cache/libmemcached-${LIBMEMCACHED_VERSION}" # Where to do the build PHP_MEMCACHED_BUILD_DIR="/tmp/php-memcached-build" From 852d60cbc726532310abf598c6ea391b0c6407c4 Mon Sep 17 00:00:00 2001 From: Mikko Date: Sat, 16 Jan 2016 22:00:30 +0000 Subject: [PATCH 03/15] More travis updates --- .travis.yml | 11 ++++++++++- .travis/travis.sh | 1 - 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 188bedba..c60ed89c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,11 @@ env: - LIBMEMCACHED_VERSION=0.53 - LIBMEMCACHED_VERSION=0.49 - LIBMEMCACHED_VERSION=0.44 +addons: + apt: + packages: + - sasl2-bin + - libsasl2-dev services: - memcached # will start memcached @@ -25,6 +30,10 @@ before_script: script: - ./.travis/travis.sh script $LIBMEMCACHED_VERSION +sudo: false + cache: directories: - - $HOME/cache \ No newline at end of file + - $HOME/cache + + \ No newline at end of file diff --git a/.travis/travis.sh b/.travis/travis.sh index e87a372f..923eb518 100755 --- a/.travis/travis.sh +++ b/.travis/travis.sh @@ -106,7 +106,6 @@ function install_sasl() { make install popd - sudo apt-get install sasl2-bin export SASL_CONF_PATH="${HOME}/cache/sasl2" # Create config path From f3bfce3ec85e7aa8a25a28de1bc04bb0263df993 Mon Sep 17 00:00:00 2001 From: Mikko Date: Sat, 16 Jan 2016 22:17:21 +0000 Subject: [PATCH 04/15] Run our own memcached --- .travis.yml | 4 +--- .travis/travis.sh | 40 ++++++++++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index c60ed89c..30e5c3e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ php: - 7.0 env: + - LIBMEMCACHED_VERSION=1.0.18 - LIBMEMCACHED_VERSION=1.0.17 - LIBMEMCACHED_VERSION=1.0.16 - LIBMEMCACHED_VERSION=1.0.15 @@ -21,9 +22,6 @@ addons: - sasl2-bin - libsasl2-dev -services: - - memcached # will start memcached - before_script: - ./.travis/travis.sh before_script $LIBMEMCACHED_VERSION diff --git a/.travis/travis.sh b/.travis/travis.sh index 923eb518..a80e0cf3 100755 --- a/.travis/travis.sh +++ b/.travis/travis.sh @@ -1,5 +1,7 @@ #!/bin/bash +MEMCACHED_VERSION="1.4.25" + function version_compare() { DPKG=`which dpkg` @@ -87,27 +89,35 @@ function install_msgpack() { popd } -function install_sasl() { - +function install_memcached() { local prefix="${HOME}/cache/memcached" - if test -f "${prefix}/bin/memcached" + if test -d "$prefix" then - echo "Using cached memcached-sasl: ${prefix}/bin/memcached" + echo "Using cached memcached: ${prefix}" return fi - wget http://www.memcached.org/files/memcached-1.4.25.tar.gz -O memcached-1.4.25.tar.gz - tar xfz memcached-1.4.25.tar.gz + wget http://www.memcached.org/files/memcached-${MEMCACHED_VERSION}.tar.gz -O memcached-${MEMCACHED_VERSION}.tar.gz + tar xfz memcached-${MEMCACHED_VERSION}.tar.gz - pushd memcached-1.4.25 + pushd memcached-${MEMCACHED_VERSION} ./configure --enable-sasl --prefix="${prefix}" make make install popd +} + +function install_sasl_config() { export SASL_CONF_PATH="${HOME}/cache/sasl2" + if test -f "${SASL_CONF_PATH}/memcached.conf" + then + echo "Using cached SASL configuration: ${SASL_CONF_PATH}/memcached.conf" + return + fi + # Create config path mkdir "${SASL_CONF_PATH}" @@ -120,6 +130,13 @@ EOF # Create password echo "test" | /usr/sbin/saslpasswd2 -c memcached -a memcached -f "${SASL_CONF_PATH}/sasldb2" +} + +function run_memcached() { + local prefix="${HOME}/cache/memcached" + + # Run normal memcached + "${prefix}/bin/memcached" -d -p 11211 # Run memcached on port 11212 with SASL support "${prefix}/bin/memcached" -S -d -p 11212 @@ -232,11 +249,10 @@ case $ACTION in # install msgpack # install_msgpack - - # install SASL - if test "x$ENABLE_SASL" = "xyes"; then - install_sasl - fi + + install_memcached + install_sasl_config + run_memcached ;; script) From dcdd3b88c57f6ee2fc43d20f1ec7ad7444c42be5 Mon Sep 17 00:00:00 2001 From: Mikko Date: Sat, 16 Jan 2016 22:22:25 +0000 Subject: [PATCH 05/15] Allow specifying memcached version --- .travis/travis.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis/travis.sh b/.travis/travis.sh index a80e0cf3..78ae9ffb 100755 --- a/.travis/travis.sh +++ b/.travis/travis.sh @@ -1,7 +1,5 @@ #!/bin/bash -MEMCACHED_VERSION="1.4.25" - function version_compare() { DPKG=`which dpkg` @@ -90,7 +88,7 @@ function install_msgpack() { } function install_memcached() { - local prefix="${HOME}/cache/memcached" + local prefix="${HOME}/cache/memcached-${MEMCACHED_VERSION}" if test -d "$prefix" then @@ -133,7 +131,7 @@ EOF } function run_memcached() { - local prefix="${HOME}/cache/memcached" + local prefix="${HOME}/cache/memcached-${MEMCACHED_VERSION}" # Run normal memcached "${prefix}/bin/memcached" -d -p 11211 @@ -207,6 +205,7 @@ function run_memcached_tests() { # Command line arguments ACTION=$1 LIBMEMCACHED_VERSION=$2 +MEMCACHED_VERSION="1.4.25" if test "x$ACTION" = "x"; then echo "Usage: $0 " @@ -218,6 +217,10 @@ if test "x$LIBMEMCACHED_VERSION" = "x"; then exit 1 fi +if test "x$3" != "x"; then + MEMCACHED_VERSION=$3 +fi + # the extension version PHP_MEMCACHED_VERSION=$(php -r '$sxe = simplexml_load_file ("package.xml"); echo (string) $sxe->version->release;') From 5eb3bfd4fe8a6532ad80fc784020e70fabfedfec Mon Sep 17 00:00:00 2001 From: Mikko Date: Mon, 18 Jan 2016 04:05:32 +0000 Subject: [PATCH 06/15] Fixes to keys and tests --- php_memcached.c | 14 +++++++------- tests/keys.phpt | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/php_memcached.c b/php_memcached.c index c7fb08ba..f5a9ea22 100644 --- a/php_memcached.c +++ b/php_memcached.c @@ -424,6 +424,7 @@ static PHP_METHOD(Memcached, __construct) } i_obj->is_persistent = is_persistent; + array_init(&i_obj->last_udf_flags); if (!m_obj) { m_obj = pecalloc(1, sizeof(*m_obj), is_persistent); @@ -470,7 +471,6 @@ static PHP_METHOD(Memcached, __construct) m_obj->store_retry_count = MEMC_G(store_retry_count); m_obj->set_udf_flags = -1; - array_init(&i_obj->last_udf_flags); i_obj->obj = m_obj; i_obj->is_pristine = 1; @@ -580,7 +580,7 @@ static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) zend_hash_clean(Z_ARRVAL(i_obj->last_udf_flags)); - if (key->len == 0) { + if (key->len == 0 || (!memcached_behavior_get(m_obj->memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) && strchr(key->val, ' '))) { i_obj->rescode = MEMCACHED_BAD_KEY_PROVIDED; RETURN_FROM_GET; } @@ -1423,7 +1423,7 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool MEMC_METHOD_FETCH_OBJECT; i_obj->rescode = MEMCACHED_SUCCESS; - if (key->len == 0) { + if (key->len == 0 || (!memcached_behavior_get(m_obj->memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) && strchr(key->val, ' '))) { i_obj->rescode = MEMCACHED_BAD_KEY_PROVIDED; RETURN_FALSE; } @@ -1568,7 +1568,7 @@ static void php_memc_cas_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) MEMC_METHOD_FETCH_OBJECT; i_obj->rescode = MEMCACHED_SUCCESS; - if (key->len == 0) { + if (key->len == 0 || (!memcached_behavior_get(m_obj->memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) && strchr(key->val, ' '))) { i_obj->rescode = MEMCACHED_BAD_KEY_PROVIDED; RETURN_FALSE; } @@ -1677,7 +1677,7 @@ static void php_memc_delete_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) MEMC_METHOD_FETCH_OBJECT; i_obj->rescode = MEMCACHED_SUCCESS; - if (key->len == 0 || strchr(key->val, ' ')) { + if (key->len == 0 || (!memcached_behavior_get(m_obj->memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) && strchr(key->val, ' '))) { i_obj->rescode = MEMCACHED_BAD_KEY_PROVIDED; RETURN_FALSE; } @@ -1775,7 +1775,7 @@ static void php_memc_incdec_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key, MEMC_METHOD_FETCH_OBJECT; i_obj->rescode = MEMCACHED_SUCCESS; - if (key->len == 0 || strchr(key->val, ' ')) { + if (key->len == 0 || (!memcached_behavior_get(m_obj->memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) && strchr(key->val, ' '))) { i_obj->rescode = MEMCACHED_BAD_KEY_PROVIDED; RETURN_FALSE; } @@ -2020,7 +2020,7 @@ PHP_METHOD(Memcached, getServerByKey) MEMC_METHOD_FETCH_OBJECT; i_obj->rescode = MEMCACHED_SUCCESS; - if (server_key->len == 0 || strchr(server_key->val, ' ')) { + if (server_key->len == 0 || (!memcached_behavior_get(m_obj->memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) && strchr(server_key->val, ' '))) { i_obj->rescode = MEMCACHED_BAD_KEY_PROVIDED; RETURN_FALSE; } diff --git a/tests/keys.phpt b/tests/keys.phpt index 0ed90896..89632f5d 100644 --- a/tests/keys.phpt +++ b/tests/keys.phpt @@ -13,7 +13,7 @@ $binary = memc_get_instance (array ( $ascii = memc_get_instance (); var_dump ($binary->set ('binary key with spaces', 'this is a test')); -var_dump ($binary->getResultCode () == Memcached::RES_BAD_KEY_PROVIDED); +var_dump ($binary->getResultCode () == Memcached::RES_SUCCESS); var_dump ($ascii->set ('ascii key with spaces', 'this is a test')); var_dump ($ascii->getResultCode () == Memcached::RES_BAD_KEY_PROVIDED); @@ -24,7 +24,7 @@ var_dump ($ascii->getResultCode () == Memcached::RES_BAD_KEY_PROVIDED); echo "OK" . PHP_EOL; --EXPECT-- -bool(false) +bool(true) bool(true) bool(false) bool(true) From 029784c6870fcd812e58f56c4a17a51e198eb2fc Mon Sep 17 00:00:00 2001 From: Mikko Date: Mon, 18 Jan 2016 04:17:19 +0000 Subject: [PATCH 07/15] Show diff --- .travis/travis.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.travis/travis.sh b/.travis/travis.sh index 78ae9ffb..a80ca77a 100755 --- a/.travis/travis.sh +++ b/.travis/travis.sh @@ -181,7 +181,7 @@ EOF function run_memcached_tests() { export NO_INTERACTION=1 export REPORT_EXIT_STATUS=1 - export TEST_PHP_EXECUTABLE=`which php` + export TEST_PHP_EXECUTABLE=$(which php) pushd "${PHP_MEMCACHED_BUILD_DIR}/memcached-${PHP_MEMCACHED_VERSION}" # We have one xfail test, we run it separately @@ -189,14 +189,8 @@ function run_memcached_tests() { rm ./tests/expire.phpt # Run normal tests - php run-tests.php -d extension=memcached.so -n ./tests/*.phpt + php run-tests.php --show-diff -d extension=memcached.so -n ./tests/*.phpt retval=$? - for i in `ls tests/*.out 2>/dev/null`; do - echo "-- START ${i}"; - cat $i; - echo ""; - echo "-- END"; - done popd return $retval; From 00d99deb90d8bcd667f7ea2d008218d8e82ab601 Mon Sep 17 00:00:00 2001 From: Mikko Date: Mon, 18 Jan 2016 04:42:16 +0000 Subject: [PATCH 08/15] Should fix sasl --- .travis/travis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/travis.sh b/.travis/travis.sh index a80ca77a..b2ef1fb7 100755 --- a/.travis/travis.sh +++ b/.travis/travis.sh @@ -137,7 +137,7 @@ function run_memcached() { "${prefix}/bin/memcached" -d -p 11211 # Run memcached on port 11212 with SASL support - "${prefix}/bin/memcached" -S -d -p 11212 + MEMCACHED_SASL_PWDB="${SASL_CONF_PATH}/sasldb2" "${prefix}/bin/memcached" -S -d -p 11212 } function build_php_memcached() { From 238a403ea87036c18982dfcb1d7d3fea26cb367b Mon Sep 17 00:00:00 2001 From: Mikko Date: Mon, 18 Jan 2016 04:45:59 +0000 Subject: [PATCH 09/15] Should fix sasl --- .travis/travis.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis/travis.sh b/.travis/travis.sh index b2ef1fb7..d841a4b3 100755 --- a/.travis/travis.sh +++ b/.travis/travis.sh @@ -88,7 +88,7 @@ function install_msgpack() { } function install_memcached() { - local prefix="${HOME}/cache/memcached-${MEMCACHED_VERSION}" + local prefix="${HOME}/cache/memcached-sasl-${MEMCACHED_VERSION}" if test -d "$prefix" then @@ -100,7 +100,7 @@ function install_memcached() { tar xfz memcached-${MEMCACHED_VERSION}.tar.gz pushd memcached-${MEMCACHED_VERSION} - ./configure --enable-sasl --prefix="${prefix}" + ./configure --enable-sasl --enable-sasl-pwdb --prefix="${prefix}" make make install popd @@ -137,7 +137,8 @@ function run_memcached() { "${prefix}/bin/memcached" -d -p 11211 # Run memcached on port 11212 with SASL support - MEMCACHED_SASL_PWDB="${SASL_CONF_PATH}/sasldb2" "${prefix}/bin/memcached" -S -d -p 11212 + export MEMCACHED_SASL_PWDB="${SASL_CONF_PATH}/sasldb2" + "${prefix}/bin/memcached" -S -d -p 11212 } function build_php_memcached() { From 5a1d092b7fafbb80bc3e6eb47ead104b10ae1ad6 Mon Sep 17 00:00:00 2001 From: Mikko Date: Mon, 18 Jan 2016 04:49:03 +0000 Subject: [PATCH 10/15] Run right memcached --- .travis/travis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/travis.sh b/.travis/travis.sh index d841a4b3..3d2af8ae 100755 --- a/.travis/travis.sh +++ b/.travis/travis.sh @@ -131,7 +131,7 @@ EOF } function run_memcached() { - local prefix="${HOME}/cache/memcached-${MEMCACHED_VERSION}" + local prefix="${HOME}/cache/memcached-sasl-${MEMCACHED_VERSION}" # Run normal memcached "${prefix}/bin/memcached" -d -p 11211 From 37f261879742d52a329e9c172ef2cce6f1a34684 Mon Sep 17 00:00:00 2001 From: Mikko Date: Mon, 18 Jan 2016 05:00:55 +0000 Subject: [PATCH 11/15] Memcached log --- .travis/travis.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis/travis.sh b/.travis/travis.sh index 3d2af8ae..96f6bc31 100755 --- a/.travis/travis.sh +++ b/.travis/travis.sh @@ -137,8 +137,11 @@ function run_memcached() { "${prefix}/bin/memcached" -d -p 11211 # Run memcached on port 11212 with SASL support + echo "SASL users:" + sasldblistusers2 -f "${SASL_CONF_PATH}/sasldb2" + export MEMCACHED_SASL_PWDB="${SASL_CONF_PATH}/sasldb2" - "${prefix}/bin/memcached" -S -d -p 11212 + "${prefix}/bin/memcached" -S -d -v -p 11212 > /tmp/memcached-sasl.log 2>&1 } function build_php_memcached() { @@ -194,6 +197,7 @@ function run_memcached_tests() { retval=$? popd + cat /tmp/memcached-sasl.log return $retval; } From 7e5f0922420ce5d4d472dcafd3e9569eec92fb8b Mon Sep 17 00:00:00 2001 From: Mikko Date: Mon, 18 Jan 2016 05:26:00 +0000 Subject: [PATCH 12/15] SASL is tricky --- .travis/travis.sh | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/.travis/travis.sh b/.travis/travis.sh index 96f6bc31..3924efd6 100755 --- a/.travis/travis.sh +++ b/.travis/travis.sh @@ -106,41 +106,32 @@ function install_memcached() { popd } -function install_sasl_config() { +function run_memcached() { + local prefix="${HOME}/cache/memcached-sasl-${MEMCACHED_VERSION}" - export SASL_CONF_PATH="${HOME}/cache/sasl2" + export SASL_CONF_PATH="/tmp/sasl2" - if test -f "${SASL_CONF_PATH}/memcached.conf" + if test -d "${SASL_CONF_PATH}" then - echo "Using cached SASL configuration: ${SASL_CONF_PATH}/memcached.conf" - return + rm -rf "${SASL_CONF_PATH}" fi - # Create config path mkdir "${SASL_CONF_PATH}" + export MEMCACHED_SASL_PWDB="${SASL_CONF_PATH}/sasldb2" # Create configuration cat< "${SASL_CONF_PATH}/memcached.conf" mech_list: PLAIN plainlog_level: 5 -sasldb_path: ${SASL_CONF_PATH}/sasldb2 +sasldb_path: ${MEMCACHED_SASL_PWDB} EOF - # Create password - echo "test" | /usr/sbin/saslpasswd2 -c memcached -a memcached -f "${SASL_CONF_PATH}/sasldb2" -} - -function run_memcached() { - local prefix="${HOME}/cache/memcached-sasl-${MEMCACHED_VERSION}" + echo "test" | /usr/sbin/saslpasswd2 -c memcached -a memcached -f "${MEMCACHED_SASL_PWDB}" # Run normal memcached "${prefix}/bin/memcached" -d -p 11211 # Run memcached on port 11212 with SASL support - echo "SASL users:" - sasldblistusers2 -f "${SASL_CONF_PATH}/sasldb2" - - export MEMCACHED_SASL_PWDB="${SASL_CONF_PATH}/sasldb2" "${prefix}/bin/memcached" -S -d -v -p 11212 > /tmp/memcached-sasl.log 2>&1 } @@ -253,7 +244,6 @@ case $ACTION in # install_msgpack install_memcached - install_sasl_config run_memcached ;; From 1aab3f70f7c6a8cac480e1244b7eafbb75bc9c40 Mon Sep 17 00:00:00 2001 From: Mikko Date: Mon, 18 Jan 2016 05:28:33 +0000 Subject: [PATCH 13/15] Remove debug logging --- .travis/travis.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis/travis.sh b/.travis/travis.sh index 3924efd6..a6240d83 100755 --- a/.travis/travis.sh +++ b/.travis/travis.sh @@ -132,7 +132,7 @@ EOF "${prefix}/bin/memcached" -d -p 11211 # Run memcached on port 11212 with SASL support - "${prefix}/bin/memcached" -S -d -v -p 11212 > /tmp/memcached-sasl.log 2>&1 + "${prefix}/bin/memcached" -S -d -v -p 11212 } function build_php_memcached() { @@ -187,8 +187,6 @@ function run_memcached_tests() { php run-tests.php --show-diff -d extension=memcached.so -n ./tests/*.phpt retval=$? popd - - cat /tmp/memcached-sasl.log return $retval; } From e6946ee636b6db6dae60b0c9067a9def42b4cbbc Mon Sep 17 00:00:00 2001 From: Mikko Date: Mon, 18 Jan 2016 05:30:26 +0000 Subject: [PATCH 14/15] Remove debug logging --- .travis/travis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/travis.sh b/.travis/travis.sh index a6240d83..131e38bf 100755 --- a/.travis/travis.sh +++ b/.travis/travis.sh @@ -132,7 +132,7 @@ EOF "${prefix}/bin/memcached" -d -p 11211 # Run memcached on port 11212 with SASL support - "${prefix}/bin/memcached" -S -d -v -p 11212 + "${prefix}/bin/memcached" -S -d -p 11212 } function build_php_memcached() { From fd8fead6bd02f5aa28ac622b45dd2642763507af Mon Sep 17 00:00:00 2001 From: Mikko Date: Mon, 18 Jan 2016 05:41:18 +0000 Subject: [PATCH 15/15] Remove really old libmemcached versions. If anyone is using this old version they should be worried --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 30e5c3e1..fb0d0fbe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,9 +13,9 @@ env: - LIBMEMCACHED_VERSION=1.0.7 - LIBMEMCACHED_VERSION=1.0.6 - LIBMEMCACHED_VERSION=1.0.2 - - LIBMEMCACHED_VERSION=0.53 - - LIBMEMCACHED_VERSION=0.49 - - LIBMEMCACHED_VERSION=0.44 + #- LIBMEMCACHED_VERSION=0.53 + #- LIBMEMCACHED_VERSION=0.49 + #- LIBMEMCACHED_VERSION=0.44 addons: apt: packages: