You are here

function _dmemcache_ascii_authenticate_server in Memcache API and Integration 7

Performs ascii authentication to the server given by host and port.

Parameters

string $host: The hostname of the server to authenticate to.

int $port: The port of the server to authenticate to.

object $mc: The memcache object.

Return value

bool TRUE on success, FALSE otherwise.

2 calls to _dmemcache_ascii_authenticate_server()
dmemcache_connect in ./dmemcache.inc
Initiate a connection to memcache.
_dmemcache_reset_ascii_auth in ./dmemcache.inc
If using ascii authentication, re-authenticates all servers.

File

./dmemcache.inc, line 1404
A memcache API for Drupal.

Code

function _dmemcache_ascii_authenticate_server($host, $port, $mc) {
  $rc = FALSE;

  // Find a working key that matches the specified server.
  for ($key = 0; $key < 1000; $key++) {

    // It's impossible to directly address a server, but we need to
    // login to the specified connection before it can be used.
    // So we check all keys from 0 to 1000 if it would map to this server.
    // Once we have found one, we set the authentication data, because any key
    // will work for authentication as the authentication data includes user and
    // password.
    $s = $mc
      ->getServerByKey($key);
    if ($s['host'] == $host && $s['port'] == $port) {
      $rc = _dmemcache_ensure_ascii_auth($key, $mc);
      break;
    }
  }

  // This should never happen.
  if ($key == 1000) {
    register_shutdown_function('watchdog', 'memcache', 'Memcache ascii authentication could not find the server to authenticate to.', array(), WATCHDOG_ERROR);
    return FALSE;
  }
  return $rc;
}