You are here

function memcache_enable in Memcache API and Integration 6

Same name and namespace in other branches
  1. 7 memcache.install \memcache_enable()

Implements hook_enable().

File

./memcache.install, line 14
Install, update and uninstall functions for the memcache module.

Code

function memcache_enable() {
  $error = FALSE;
  $warning = FALSE;
  $severity = 'status';
  $memcache = extension_loaded('memcache');
  $memcached = extension_loaded('memcached');
  if (!$memcache && !$memcached) {
    $error = TRUE;
  }
  if (!function_exists('dmemcache_object')) {

    // dmemcache.inc isn't loaded.
    $error = TRUE;
  }
  else {
    if (!_memcache_version_valid()) {
      $warning = TRUE;
    }

    // Make a test connection to all configured memcache servers.
    $memcache_servers = variable_get('memcache_servers', array(
      '127.0.0.1:11211' => 'default',
    ));
    $memcache = dmemcache_instance();
    foreach ($memcache_servers as $server => $bin) {
      if (dmemcache_connect($memcache, $server, FALSE) === FALSE) {
        $error = TRUE;
      }
      else {
        dmemcache_close($memcache);
      }
    }
  }
  if ($error) {
    $severity = 'error';
  }
  elseif ($warning) {
    $severity = 'warning';
  }
  if ($error || $warning) {
    drupal_set_message(t('There are problems with your Memcache configuration. Please review %readme and visit the Drupal admin !status page for more information.', array(
      '%readme' => 'README.txt',
      '!status' => l(t('status report'), 'admin/reports/status'),
    )), $severity);
  }
}