Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -659,6 +663,10 @@ function sort_list(&$list) {
</table>
</div>
<?php endif; ?>
<?php elseif($memcacheVersion == 'memcached-bin'): ?>
<p style="text-align: center">
When SASL authentication is enabled on the <a href="https://pecl.php.net/package/memcached">memcached extension</a> we can not support listing keys
</p>
<?php else: ?>
<p style="text-align: center">
Legacy <a href="https://pecl.php.net/package/memcache">memcache extension</a> does not support listing keys
Expand Down
4 changes: 3 additions & 1 deletion demo/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down