From 7b7d73a733e8933fd66d6a5a2964c6d6a38e073e Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Fri, 10 Feb 2017 06:23:57 -0800 Subject: [PATCH 01/10] Add warning for memcached_touch in binary protocol mode with libmemcached < 1.0.18 --- php_libmemcached_compat.c | 21 +++++++++++++++++++++ php_libmemcached_compat.h | 3 +++ php_memcached.c | 4 ++-- php_memcached_session.c | 2 +- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/php_libmemcached_compat.c b/php_libmemcached_compat.c index bd35d8fe..a703cac5 100644 --- a/php_libmemcached_compat.c +++ b/php_libmemcached_compat.c @@ -35,3 +35,24 @@ memcached_return php_memcached_exist (memcached_st *memc, zend_string *key) return rc; #endif } + +memcached_return php_memcached_touch(memcached_st *memc, const char *key, size_t key_len, time_t expiration) +{ +#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX < 0x01000018 + if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) { + php_error_docref(NULL, E_WARNING, "memcached binary protocol touch command is broken in libmemcached < 1.0.18, please use ascii protocol or upgrade libmemcached"); + } +#endif + return memcached_touch(memc, key, key_len, expiration); +} + +memcached_return php_memcached_touch_by_key(memcached_st *memc, const char *server_key, size_t server_key_len, const char *key, size_t key_len, time_t expiration) +{ +#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX < 0x01000018 + if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) { + php_error_docref(NULL, E_WARNING, "memcached binary protocol touch command is broken in libmemcached < 1.0.18, please use ascii protocol or upgrade libmemcached"); + } +#endif + return memcached_touch_by_key(memc, server_key, server_key_len, key, key_len, expiration); +} + diff --git a/php_libmemcached_compat.h b/php_libmemcached_compat.h index 9bcbc20f..42a409dc 100644 --- a/php_libmemcached_compat.h +++ b/php_libmemcached_compat.h @@ -22,6 +22,9 @@ memcached_return php_memcached_exist (memcached_st *memc, zend_string *key); +memcached_return php_memcached_touch(memcached_st *memc, const char *key, size_t key_len, time_t expiration); +memcached_return php_memcached_touch_by_key(memcached_st *memc, const char *server_key, size_t server_key_len, const char *key, size_t key_len, time_t expiration); + #if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x01000017 typedef const memcached_instance_st * php_memcached_instance_st; #else diff --git a/php_memcached.c b/php_memcached.c index d6f42575..94eaaad7 100644 --- a/php_memcached.c +++ b/php_memcached.c @@ -1081,7 +1081,7 @@ zend_bool s_memc_write_zval (php_memc_object_t *intern, php_memc_write_op op, ze break; case MEMC_OP_TOUCH: - status = memcached_touch_by_key(intern->memc, ZSTR_VAL(server_key), ZSTR_LEN(server_key), ZSTR_VAL(key), ZSTR_LEN(key), expiration); + status = php_memcached_touch_by_key(intern->memc, ZSTR_VAL(server_key), ZSTR_LEN(server_key), ZSTR_VAL(key), ZSTR_LEN(key), expiration); break; case MEMC_OP_ADD: @@ -1113,7 +1113,7 @@ zend_bool s_memc_write_zval (php_memc_object_t *intern, php_memc_write_op op, ze break; case MEMC_OP_TOUCH: - status = memcached_touch(intern->memc, ZSTR_VAL(key), ZSTR_LEN(key), expiration); + status = php_memcached_touch(intern->memc, ZSTR_VAL(key), ZSTR_LEN(key), expiration); break; case MEMC_OP_ADD: diff --git a/php_memcached_session.c b/php_memcached_session.c index 1695b330..b6d93c5f 100644 --- a/php_memcached_session.c +++ b/php_memcached_session.c @@ -542,7 +542,7 @@ PS_UPDATE_TIMESTAMP_FUNC(memcached) memcached_st *memc = PS_GET_MOD_DATA(); time_t expiration = s_session_expiration(maxlifetime); - if (memcached_touch(memc, key->val, key->len, expiration) == MEMCACHED_FAILURE) { + if (php_memcached_touch(memc, key->val, key->len, expiration) == MEMCACHED_FAILURE) { return FAILURE; } return SUCCESS; From 995a0d0d1e02a4b921a43390bdfdcfea81afabf1 Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Fri, 10 Feb 2017 13:58:43 -0800 Subject: [PATCH 02/10] Adjust tests for the new warning message --- package.xml | 1 + tests/gh_155.phpt | 7 +++-- tests/session_basic.phpt | 1 + tests/session_basic2.phpt | 1 + tests/session_basic3.phpt | 1 + tests/session_lazy_warning.phpt | 46 +++++++++++++++++++++++++++++++++ tests/session_lock.phpt | 1 + tests/touch_binary.phpt | 5 +++- 8 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 tests/session_lazy_warning.phpt diff --git a/package.xml b/package.xml index 7aadf4db..a5c7c07b 100644 --- a/package.xml +++ b/package.xml @@ -157,6 +157,7 @@ Fixes + diff --git a/tests/gh_155.phpt b/tests/gh_155.phpt index a5b61d00..699e8eca 100644 --- a/tests/gh_155.phpt +++ b/tests/gh_155.phpt @@ -4,7 +4,10 @@ Test for bug 155 --FILE-- setOption(Memcached::OPT_BINARY_PROTOCOL,true); +$m->setOption(Memcached::OPT_BINARY_PROTOCOL, true); $m->addServer(MEMC_SERVER_HOST, MEMC_SERVER_PORT); $key = 'bug_155_' . uniqid(); diff --git a/tests/session_basic.phpt b/tests/session_basic.phpt index 3fdb6bd7..01421610 100644 --- a/tests/session_basic.phpt +++ b/tests/session_basic.phpt @@ -7,6 +7,7 @@ if (!Memcached::HAVE_SESSION) print "skip"; ?> --INI-- session.save_handler = memcached +memcached.sess_binary = Off --FILE-- --INI-- session.save_handler = memcached +memcached.sess_binary = Off --FILE-- --INI-- session.save_handler = memcached +memcached.sess_binary = Off --FILE-- = 0x01000018) die ('skip too old libmemcached'); +?> +--INI-- +session.save_handler = memcached +memcached.sess_binary = On +--FILE-- +TRUE]); +$_SESSION['foo'] = 1; +session_write_close(); + +$_SESSION = NULL; + +var_dump($_SESSION); +session_start(); +var_dump($_SESSION); +session_write_close(); + +session_start(); +session_destroy(); + +session_start(); +var_dump($_SESSION); +session_write_close(); + + +--EXPECT-- +NULL +array(1) { + ["foo"]=> + int(1) +} +Warning: Memcached::touch(): memcached binary protocol touch command is broken in libmemcached < 1.0.18, please use ascii protocol or upgrade libmemcached in %s on line %d +array(0) { +} diff --git a/tests/session_lock.phpt b/tests/session_lock.phpt index 570e5a2a..d9869c09 100644 --- a/tests/session_lock.phpt +++ b/tests/session_lock.phpt @@ -13,6 +13,7 @@ memcached.sess_lock_wait_min = 500 memcached.sess_lock_wait_max = 1000 memcached.sess_lock_retries = 3 memcached.sess_prefix = "memc.test." +memcached.sess_binary = Off session.save_handler = memcached diff --git a/tests/touch_binary.phpt b/tests/touch_binary.phpt index cc35e8fb..382c1778 100644 --- a/tests/touch_binary.phpt +++ b/tests/touch_binary.phpt @@ -4,7 +4,10 @@ Touch in binary mode --FILE-- Date: Sun, 12 Feb 2017 05:53:41 -0800 Subject: [PATCH 03/10] memcached.sess_binary was renamed to memcached.sess_binary_protocol --- tests/session_basic.phpt | 2 +- tests/session_basic2.phpt | 2 +- tests/session_basic3.phpt | 2 +- tests/session_lazy_warning.phpt | 2 +- tests/session_lock.phpt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/session_basic.phpt b/tests/session_basic.phpt index 01421610..0e8b3469 100644 --- a/tests/session_basic.phpt +++ b/tests/session_basic.phpt @@ -7,7 +7,7 @@ if (!Memcached::HAVE_SESSION) print "skip"; ?> --INI-- session.save_handler = memcached -memcached.sess_binary = Off +memcached.sess_binary_protocol = Off --FILE-- --INI-- session.save_handler = memcached -memcached.sess_binary = Off +memcached.sess_binary_protocol = Off --FILE-- --INI-- session.save_handler = memcached -memcached.sess_binary = Off +memcached.sess_binary_protocol = Off --FILE-- = 0x01000018) die ('skip too old libmem ?> --INI-- session.save_handler = memcached -memcached.sess_binary = On +memcached.sess_binary_protocol = On --FILE-- Date: Sun, 12 Feb 2017 06:07:24 -0800 Subject: [PATCH 04/10] fixmessage --- tests/session_lazy_warning.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/session_lazy_warning.phpt b/tests/session_lazy_warning.phpt index 2cfbb7f1..e702700c 100644 --- a/tests/session_lazy_warning.phpt +++ b/tests/session_lazy_warning.phpt @@ -41,6 +41,6 @@ array(1) { ["foo"]=> int(1) } -Warning: Memcached::touch(): memcached binary protocol touch command is broken in libmemcached < 1.0.18, please use ascii protocol or upgrade libmemcached in %s on line %d +Warning: session_write_close(): memcached binary protocol touch command is broken in libmemcached < 1.0.18, please use ascii protocol or upgrade libmemcached in %s on line %d array(0) { } From fc2a5276f87ca44bbf40b9c22f2e72bad76946b3 Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Sun, 12 Feb 2017 06:18:14 -0800 Subject: [PATCH 05/10] space --- tests/session_lazy_warning.phpt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/session_lazy_warning.phpt b/tests/session_lazy_warning.phpt index e702700c..cf8ba7bf 100644 --- a/tests/session_lazy_warning.phpt +++ b/tests/session_lazy_warning.phpt @@ -41,6 +41,7 @@ array(1) { ["foo"]=> int(1) } + Warning: session_write_close(): memcached binary protocol touch command is broken in libmemcached < 1.0.18, please use ascii protocol or upgrade libmemcached in %s on line %d array(0) { } From 9ba58a0630a7cdce1518d4c48767a123fd08f4f3 Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Sun, 12 Feb 2017 06:28:00 -0800 Subject: [PATCH 06/10] F --- tests/session_lazy_warning.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/session_lazy_warning.phpt b/tests/session_lazy_warning.phpt index cf8ba7bf..dc058da4 100644 --- a/tests/session_lazy_warning.phpt +++ b/tests/session_lazy_warning.phpt @@ -35,7 +35,7 @@ var_dump($_SESSION); session_write_close(); ---EXPECT-- +--EXPECTF-- NULL array(1) { ["foo"]=> From b3d3b88a06eb4414805570ddc695c62539b894bb Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Sun, 12 Feb 2017 06:34:54 -0800 Subject: [PATCH 07/10] Turn off binary protocol while the test matrix has older versions of libmemcached for which the extension warns of a broken touch command --- tests/session_lock-php71.phpt | 4 ++++ tests/session_lock.phpt | 3 +++ 2 files changed, 7 insertions(+) diff --git a/tests/session_lock-php71.phpt b/tests/session_lock-php71.phpt index 207f64cf..c0fceb67 100644 --- a/tests/session_lock-php71.phpt +++ b/tests/session_lock-php71.phpt @@ -14,6 +14,10 @@ memcached.sess_lock_wait_max = 1000 memcached.sess_lock_retries = 3 memcached.sess_prefix = "memc.test." +# Turn off binary protocol while the test matrix has older versions of +# libmemcached for which the extension warns of a broken touch command. +memcached.sess_binary_protocol = Off + session.save_handler = memcached --FILE-- diff --git a/tests/session_lock.phpt b/tests/session_lock.phpt index a24427c9..cedc83bb 100644 --- a/tests/session_lock.phpt +++ b/tests/session_lock.phpt @@ -13,6 +13,9 @@ memcached.sess_lock_wait_min = 500 memcached.sess_lock_wait_max = 1000 memcached.sess_lock_retries = 3 memcached.sess_prefix = "memc.test." + +# Turn off binary protocol while the test matrix has older versions of +# libmemcached for which the extension warns of a broken touch command. memcached.sess_binary_protocol = Off session.save_handler = memcached From c3035c64dd99f137e53dd176dcbc5d48cf512bbf Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Sun, 12 Feb 2017 06:49:18 -0800 Subject: [PATCH 08/10] Reuse the existing warning about binary protcol touch command --- php_libmemcached_compat.c | 5 +++-- php_memcached.c | 9 --------- tests/session_lazy_warning.phpt | 2 +- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/php_libmemcached_compat.c b/php_libmemcached_compat.c index a703cac5..bb0db2a1 100644 --- a/php_libmemcached_compat.c +++ b/php_libmemcached_compat.c @@ -40,7 +40,7 @@ memcached_return php_memcached_touch(memcached_st *memc, const char *key, size_t { #if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX < 0x01000018 if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) { - php_error_docref(NULL, E_WARNING, "memcached binary protocol touch command is broken in libmemcached < 1.0.18, please use ascii protocol or upgrade libmemcached"); + php_error_docref(NULL, E_WARNING, "using touch command with binary protocol is not recommended with libmemcached versions below 1.0.18, please use ascii protocol or upgrade libmemcached"); } #endif return memcached_touch(memc, key, key_len, expiration); @@ -50,7 +50,8 @@ memcached_return php_memcached_touch_by_key(memcached_st *memc, const char *serv { #if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX < 0x01000018 if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) { - php_error_docref(NULL, E_WARNING, "memcached binary protocol touch command is broken in libmemcached < 1.0.18, please use ascii protocol or upgrade libmemcached"); + php_error_docref(NULL, E_WARNING, "using touch command with binary protocol is not recommended with libmemcached versions below 1.0.18, please use ascii protocol or upgrade libmemcached"); + } } #endif return memcached_touch_by_key(memc, server_key, server_key_len, key, key_len, expiration); diff --git a/php_memcached.c b/php_memcached.c index 94eaaad7..19673323 100644 --- a/php_memcached.c +++ b/php_memcached.c @@ -1959,15 +1959,6 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool } } - - if (op == MEMC_OP_TOUCH) { -#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX < 0x01000016 - if (memcached_behavior_get(intern->memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) { - php_error_docref(NULL, E_WARNING, "using touch command with binary protocol is not recommended with libmemcached versions below 1.0.16"); - } -#endif - } - if (!s_memc_write_zval (intern, op, server_key, key, value, expiration)) { RETURN_FALSE; } diff --git a/tests/session_lazy_warning.phpt b/tests/session_lazy_warning.phpt index dc058da4..5d9273f1 100644 --- a/tests/session_lazy_warning.phpt +++ b/tests/session_lazy_warning.phpt @@ -42,6 +42,6 @@ array(1) { int(1) } -Warning: session_write_close(): memcached binary protocol touch command is broken in libmemcached < 1.0.18, please use ascii protocol or upgrade libmemcached in %s on line %d +Warning: session_write_close(): using touch command with binary protocol is not recommended with libmemcached versions below 1.0.18, please use ascii protocol or upgrade libmemcached in %s on line %d array(0) { } From 17976687e4e06d5c417fcfd99227d34e92249a30 Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Sun, 12 Feb 2017 06:50:50 -0800 Subject: [PATCH 09/10] whitespace --- tests/session_lazy_warning.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/session_lazy_warning.phpt b/tests/session_lazy_warning.phpt index 5d9273f1..79d7f2f3 100644 --- a/tests/session_lazy_warning.phpt +++ b/tests/session_lazy_warning.phpt @@ -1,8 +1,8 @@ --TEST-- Session lazy binary warning old libmemcached --SKIPIF-- -= 0x01000018) die ('skip too old libmemcached'); ?> From 12be1fdff9f00b56d4f01fe3755b54c225e60516 Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Sun, 12 Feb 2017 07:00:09 -0800 Subject: [PATCH 10/10] typo --- php_libmemcached_compat.c | 1 - 1 file changed, 1 deletion(-) diff --git a/php_libmemcached_compat.c b/php_libmemcached_compat.c index bb0db2a1..7f003b1d 100644 --- a/php_libmemcached_compat.c +++ b/php_libmemcached_compat.c @@ -52,7 +52,6 @@ memcached_return php_memcached_touch_by_key(memcached_st *memc, const char *serv if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) { php_error_docref(NULL, E_WARNING, "using touch command with binary protocol is not recommended with libmemcached versions below 1.0.18, please use ascii protocol or upgrade libmemcached"); } - } #endif return memcached_touch_by_key(memc, server_key, server_key_len, key, key_len, expiration); }