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/php_libmemcached_compat.c b/php_libmemcached_compat.c
index bd35d8fe..7f003b1d 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, "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);
+}
+
+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, "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_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..19673323 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:
@@ -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/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;
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..0e8b3469 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_protocol = Off
--FILE--
--INI--
session.save_handler = memcached
+memcached.sess_binary_protocol = Off
--FILE--
--INI--
session.save_handler = memcached
+memcached.sess_binary_protocol = Off
--FILE--
= 0x01000018) die ('skip too old libmemcached');
+?>
+--INI--
+session.save_handler = memcached
+memcached.sess_binary_protocol = 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();
+
+
+--EXPECTF--
+NULL
+array(1) {
+ ["foo"]=>
+ int(1)
+}
+
+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) {
+}
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 570e5a2a..cedc83bb 100644
--- a/tests/session_lock.phpt
+++ b/tests/session_lock.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/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--