diff --git a/includes/RadioactivityMemcachedIncidentStorage.inc b/includes/RadioactivityMemcachedIncidentStorage.inc index 0eef236..db549b3 100644 --- a/includes/RadioactivityMemcachedIncidentStorage.inc +++ b/includes/RadioactivityMemcachedIncidentStorage.inc @@ -15,14 +15,21 @@ class RadioactivityMemcachedIncidentStorage extends RadioactivityIncidentStorage * Connect to the memcache server */ private function connect() { - $mc = null; - if (class_exists("Memcache")) { $mc = new Memcache(); } - if (class_exists("Memcached")) { $mc = new Memcached(); } - $mc->addServer(VAR_RADIOACTIVITY_MEMCACHED_HOST, VAR_RADIOACTIVITY_MEMCACHED_PORT); - if (@$mc->connect(VAR_RADIOACTIVITY_MEMCACHED_HOST, VAR_RADIOACTIVITY_MEMCACHED_PORT)) { - return $mc; + if (class_exists('Memcache')) { + $mc = new Memcache(); } - return FALSE; + elseif (class_exists('Memcached')) { + $mc = new Memcached(); + } + else { + return FALSE; + } + + // Try to connect to the Memcache server. + $connected = @$mc->addServer(VAR_RADIOACTIVITY_MEMCACHED_HOST, VAR_RADIOACTIVITY_MEMCACHED_PORT); + + // If connection was successful, return the Memcache object. + return $connected ? $mc : FALSE; } /** diff --git a/plugins/export_ui/decay_profile.inc b/plugins/export_ui/decay_profile.inc index 5cc32cc..342fb67 100644 --- a/plugins/export_ui/decay_profile.inc +++ b/plugins/export_ui/decay_profile.inc @@ -69,7 +69,7 @@ function radioactivity_admin_edit_profile_form(&$form, &$form_state) { 'File' => 'File storage - write incidents to a file in php temporary directory', ); - if (class_exists('Memcache')) { + if (class_exists('Memcache') || class_exists('Memcached')) { $opts['Memcached'] = 'Memcached storage - write incidents to memcached'; } diff --git a/radioactivity-bootstrap.inc b/radioactivity-bootstrap.inc index 958e643..da2ea93 100644 --- a/radioactivity-bootstrap.inc +++ b/radioactivity-bootstrap.inc @@ -13,7 +13,7 @@ else { // We're in drupal, setup necessary vars define("VAR_RADIOACTIVITY_CHECKSUM_SALT", variable_get("radioactivity_checksum_salt", "undefined")); define("VAR_RADIOACTIVITY_TEMP_DIR", variable_get('radioactivity_temp_dir', sys_get_temp_dir())); - if (class_exists('Memcache')) { + if (class_exists('Memcache') || class_exists('Memcached')) { define("VAR_RADIOACTIVITY_MEMCACHED_HOST", variable_get("radioactivity_memcached_host", "localhost")); define("VAR_RADIOACTIVITY_MEMCACHED_PORT", variable_get("radioactivity_memcached_port", "11211")); } @@ -49,7 +49,7 @@ function _radioactivity_light_initialization() { define("VAR_RADIOACTIVITY_CHECKSUM_SALT", $var); define("VAR_RADIOACTIVITY_TEMP_DIR", variable_get('radioactivity_temp_dir', sys_get_temp_dir())); variable_set("radioactivity_config_warning", TRUE); - if (class_exists('Memcache')) { + if (class_exists('Memcache') || class_exists('Memcached')) { define("VAR_RADIOACTIVITY_MEMCACHED_HOST", variable_get("radioactivity_memcached_host", "localhost")); define("VAR_RADIOACTIVITY_MEMCACHED_PORT", variable_get("radioactivity_memcached_port", "11211")); } diff --git a/radioactivity.module b/radioactivity.module index d1e2d7c..c37e4ef 100644 --- a/radioactivity.module +++ b/radioactivity.module @@ -360,7 +360,7 @@ function radioactivity_cron() { module_load_include("inc", "radioactivity", "radioactivity-bootstrap"); - if (class_exists("Memcache")) { + if (class_exists('Memcache') || class_exists('Memcached')) { // Expose the memcache settings for the memcache processIncident call if (!defined("VAR_RADIOACTIVITY_MEMCACHED_HOST")) { define("VAR_RADIOACTIVITY_MEMCACHED_HOST", variable_get("radioactivity_memcached_host", "localhost"));