Scripts and data used for generating ZhConversion.php
[lhc/web/wiklou.git] / includes / memcached-client.php
index 217417c..bed0ebf 100644 (file)
@@ -292,7 +292,7 @@ class memcached
       
       $key = is_array($key) ? $key[1] : $key;
       
-      $this->stats['delete']++;
+      @$this->stats['delete']++;
       $cmd = "delete $key $time\r\n";
       if(!fwrite($sock, $cmd, strlen($cmd)))
       {
@@ -388,9 +388,9 @@ class memcached
       
       if ($this->_debug)
          foreach ($val as $k => $v)
-            $this->_debugprint(sprintf("MemCache: sock %s got %s => %s\r\n", $sock, $k, $v));
+            $this->_debugprint(@sprintf("MemCache: sock %s got %s => %s\r\n", serialize($sock), $k, $v));
 
-      return $val[$key];
+      return @$val[$key];
    }
 
    // }}}
@@ -649,8 +649,11 @@ class memcached
          $sock = @fsockopen($ip, $port, $errno, $errstr, $timeout);
       }
       
-      if (!$sock)
+      if (!$sock) {
+         if ($this->_debug)
+            $this->_debugprint( "Error connecting to $host: $errstr\n" );
          return false;
+      }
       return true;
    }
 
@@ -667,7 +670,7 @@ class memcached
    function _dead_sock ($sock)
    {
       $host = array_search($sock, $this->_cache_sock);
-      list ($ip, $port) = explode(":", $host);
+      @list ($ip, $port) = explode(":", $host);
       $this->_host_dead[$ip] = time() + 30 + intval(rand(0, 10));
       $this->_host_dead[$host] = $this->_host_dead[$ip];
       unset($this->_cache_sock[$host]);
@@ -737,13 +740,10 @@ class memcached
     */
    function _hashfunc ($key)
    {
-      $hash = 0;
-      for ($i=0; $i<strlen($key); $i++)
-      {
-         $hash = $hash*33 + ord($key[$i]);
-      }
-      
-      return $hash;
+      # Hash function must on [0,0x7ffffff]
+      # We take the first 31 bits of the MD5 hash, which unlike the hash 
+      # function used in a previous version of this client, works
+      return hexdec(substr(md5($key),0,8)) & 0x7fffffff;
    }
 
    // }}}
@@ -769,7 +769,7 @@ class memcached
          return null;
          
       $key = is_array($key) ? $key[1] : $key;
-      $this->stats[$cmd]++;
+      @$this->stats[$cmd]++;
       if (!fwrite($sock, "$cmd $key $amt\r\n"))
          return $this->_dead_sock($sock);