function _dmemcache_ensure_ascii_auth in Memcache API and Integration 7
Ensures memcache connection is authorized for the server that is mapped for the given key.
Parameters
string $full_key: The full key for the item whose server is checked for ascii authentication.
object $mc: The memcache object.
Return value
bool TRUE if the connection is authorized, FALSE otherwise.
7 calls to _dmemcache_ensure_ascii_auth()
- dmemcache_add in ./
dmemcache.inc - Add an item into memcache.
- dmemcache_delete in ./
dmemcache.inc - Deletes an item from the cache.
- dmemcache_get in ./
dmemcache.inc - Retrieve a value from the cache.
- dmemcache_set in ./
dmemcache.inc - Place an item into memcache.
- _check_ascii_auth in ./
memcache.install - Check that ascii authentication is setup correctly.
File
- ./
dmemcache.inc, line 1340 - A memcache API for Drupal.
Code
function _dmemcache_ensure_ascii_auth($full_key, $mc) {
static $memcache_ascii_auth = NULL;
static $memcache_ascii_auth_token = NULL;
if (!isset($memcache_ascii_auth)) {
$memcache_ascii_auth = _dmemcache_use_ascii_auth();
$memcache_ascii_auth_token = variable_get('memcache_ascii_auth', FALSE);
}
// Immediately return if there is no memcache authentication.
if (!$memcache_ascii_auth) {
return FALSE;
}
// Login to the server.
$rc = $mc
->setByKey($full_key, DRUPAL_MEMCACHE_ASCII_AUTH_KEY, $memcache_ascii_auth_token);
if (!$rc && $mc
->getResultCode() == MEMCACHED_SERVER_TIMED_OUT) {
// Quitting is the only way to recover from this failure.
$mc
->quit();
$rc = $mc
->setByKey($full_key, DRUPAL_MEMCACHE_ASCII_AUTH_KEY, $memcache_ascii_auth_token);
}
if (!$rc) {
$code = $mc
->getResultCode();
$message = $mc
->getResultMessage();
$t = explode(' ', $memcache_ascii_auth_token);
$s = $mc
->getServerByKey($full_key);
register_shutdown_function('watchdog', 'memcache', 'Memcache ascii authentication failed to login with user %user to server: %server; error code: %code with message %message', array(
'%server' => $s['host'] . ':' . $s['port'],
'%user' => $t[0],
'%code' => $code,
'%message' => $message,
), WATCHDOG_ERROR);
return FALSE;
}
// Login was successful, check if our lifetime key exists already.
$rc = $mc
->getByKey($full_key, DRUPAL_MEMCACHE_ASCII_AUTH_LIFETIME_KEY);
if ($rc) {
return TRUE;
}
// Set the lifetime key.
$mc
->setByKey($full_key, DRUPAL_MEMCACHE_ASCII_AUTH_LIFETIME_KEY, TRUE);
// Confirm the lifetime key properly set, setByKey() can return success
// even when it fails.
return $mc
->getByKey($full_key, DRUPAL_MEMCACHE_ASCII_AUTH_LIFETIME_KEY);
}