diff --git a/cache.php b/cache.php index f96533c..76146b0 100644 --- a/cache.php +++ b/cache.php @@ -51,8 +51,11 @@ function __construct($search = null) { parent::__construct('user', $search); } $memcache = new \Memcached(); $memcacheVersion = 'memcached'; $memcache->addServer(MEMCACHE_HOST, MEMCACHE_PORT); - if (!empty(MEMCACHE_USER) && !empty(MEMCACHE_PASSWORD)) + if (!empty(MEMCACHE_USER) && !empty(MEMCACHE_PASSWORD)) { + $memcacheVersion = 'memcached-bin'; + $memcache->setOption(Memcached::OPT_BINARY_PROTOCOL, true); $memcache->setSaslAuthData(MEMCACHE_USER, MEMCACHE_PASSWORD); + } $memcache_stats = $memcache->getStats(); } else if (extension_loaded('memcache')) { // This extension does not support SASL authentication @@ -203,10 +206,11 @@ function memcache_get_key($key, &$found = false) { function memcache_ref() { global $memcache; + global $memcacheVersion; // Listing keys is not supported using the legacy Memcache module // PHP 7 and newer do not support this extension anymore - if (!extension_loaded('memcached')) + if ($memcacheVersion != 'memcached') return array(); $items = $memcache->getAllKeys(); @@ -659,6 +663,10 @@ function sort_list(&$list) { + +
+ When SASL authentication is enabled on the memcached extension we can not support listing keys +
Legacy memcache extension does not support listing keys diff --git a/demo/index.php b/demo/index.php index 71fee98..55c5fb7 100644 --- a/demo/index.php +++ b/demo/index.php @@ -37,8 +37,10 @@ class CacheDemoClass { $memcache = new \Memcached(); $memcache->addServer($memcache_host, $memcache_port); - if (!empty($memcache_user) && !empty($memcache_password)) + if (!empty($memcache_user) && !empty($memcache_password)) { + $memcache->setOption(Memcached::OPT_BINARY_PROTOCOL, true); $memcache->setSaslAuthData($memcache_user, $memcache_password); + } $memcache->add('type.array', ['abc', 'def']); $memcache->add('type.string', 'hello-world');