? memcache-.patch
? memcache-1011000.patch
Index: dmemcache.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/memcache/dmemcache.inc,v
retrieving revision 1.1.2.7.2.21
diff -u -p -r1.1.2.7.2.21 dmemcache.inc
--- dmemcache.inc	3 Nov 2010 19:18:42 -0000	1.1.2.7.2.21
+++ dmemcache.inc	31 Dec 2010 00:15:42 -0000
@@ -107,7 +107,7 @@ function dmemcache_get($key, $bin = 'cac
       // try and grab a lock.  If we get the lock, we return FALSE instead of
       // the cached object which should cause it to be rebuilt.  If we do not
       // get the lock, we return the cached object.  The goal here is to avoid
-      // cache stampedes. 
+      // cache stampedes.
       // By default the cache stampede semaphore is held for 15 seconds.  This
       // can be adjusted by setting the memcache_stampede_semaphore variable.
       // TODO: Can we log when a sempahore expires versus being intentionally
@@ -208,7 +208,7 @@ function dmemcache_stats($bin = 'cache',
   if ($mc = dmemcache_object($bin)) {
     // The PHP Memcache extension 3.x version throws an error if the stats
     // type is NULL or not in {reset, malloc, slabs, cachedump, items, sizes}.
-    // If $type is 'default', then no parameter should be passed to the 
+    // If $type is 'default', then no parameter should be passed to the
     // Memcache memcache_get_extended_stats() function.
     if ($type == 'default' || $type == '') {
       if (class_exists('Memcached')) {
@@ -220,7 +220,7 @@ function dmemcache_stats($bin = 'cache',
     }
     else {
       if (class_exists('Memcached')) {
-        return $mc->getStats();        
+        return $mc->getStats();
       }
       else if (class_exists('Memcache')) {
         return $mc->getExtendedStats($type);
@@ -305,10 +305,17 @@ function dmemcache_object($bin = NULL, $
 
           // This is a server that belongs to this cluster.
           if (!class_exists('Memcached') && !$init) {
+            $track_errors = ini_set('track_errors', '1');
+            $php_errormsg = '';
             // If using PECL memcache extension, use ->connect for first server
-            if ($memcache->connect($host, $port)) {
+            if (@$memcache->connect($host, $port)) {
               $init = TRUE;
             }
+            if (!empty($php_errormsg)) {
+              dmemcache_error('memcache', 'Exception caught: !msg', array('!msg' => $php_errormsg), WATCHDOG_WARNING);
+              $php_errormsg = '';
+            }
+            ini_set('track_errors', $track_errors);
           }
           else {
             if ($memcache->addServer($host, $port) && !$init) {
@@ -357,3 +364,50 @@ function dmemcache_key($key, $bin = 'cac
 
   return $full_key;
 }
+
+/**
+ * Log a system message while in the bootstrap phase.
+ *
+ * This will register its self as a shutdown fucntion.
+ * @see watchdog()
+ *
+ * @param $type
+ *   The category to which this message belongs. Can be any string, but the
+ *   general practice is to use the name of the module calling watchdog().
+ * @param $message
+ *   The message to store in the log. See t() for documentation
+ *   on how $message and $variables interact. Keep $message
+ *   translatable by not concatenating dynamic values into it!
+ * @param $variables
+ *   Array of variables to replace in the message on display or
+ *   NULL if message is already translated or not possible to
+ *   translate.
+ * @param $severity
+ *   The severity of the message, as per RFC 3164. Possible values are
+ *   WATCHDOG_ERROR, WATCHDOG_WARNING, etc.
+ * @param $link
+ *   A link to associate with the message.
+ *
+ * @see watchdog_severity_levels()
+ */
+function dmemcache_error($type = '', $message = '', $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) {
+  static $errors = array();
+  static $registered = FALSE;
+
+  $args = array($type, $message, $variables, $severity, $link);
+  if (!empty($type)) {
+    $errors[] = $args;
+    if (!$registered) {
+      register_shutdown_function(__FUNCTION__);
+      $registered = TRUE;
+    }
+    return;
+  }
+
+  if (!empty($errors)) {
+    foreach ($errors as $key => $error) {
+      watchdog($error[0], $error[1], $error[2], $error[3], $error[4]);
+      unset($errors[$key]);
+    }
+  }
+}
