typo
[lhc/web/wiklou.git] / includes / memcached-client.php
index 363c610..2752180 100644 (file)
@@ -221,11 +221,11 @@ class memcached
     */
    function memcached ($args)
    {
-      $this->set_servers($args['servers']);
-      $this->_debug = $args['debug'];
+      $this->set_servers(@$args['servers']);
+      $this->_debug = @$args['debug'];
       $this->stats = array();
-      $this->_compress_threshold = $args['compress_threshold'];
-      $this->_persistant = isset($args['persistant']) ? $args['persistant'] : false;
+      $this->_compress_threshold = @$args['compress_threshold'];
+      $this->_persistant = array_key_exists('persistant', $args) ? (@$args['persistant']) : false;
       $this->_compress_enable = true;
       $this->_have_zlib = function_exists("gzcompress");
       
@@ -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)))
       {
@@ -302,7 +302,7 @@ class memcached
       $res = trim(fgets($sock));
       
       if ($this->_debug)
-         printf("MemCache: delete %s (%s)\n", $key, $res);
+         $this->_debugprint(sprintf("MemCache: delete %s (%s)\n", $key, $res));
       
       if ($res == "DELETED")
          return true;
@@ -374,7 +374,7 @@ class memcached
       if (!is_resource($sock))
          return false;
          
-      $this->stats['get']++;
+      @$this->stats['get']++;
       
       $cmd = "get $key\r\n";
       if (!fwrite($sock, $cmd, strlen($cmd)))
@@ -388,9 +388,9 @@ class memcached
       
       if ($this->_debug)
          foreach ($val as $k => $v)
-            printf("MemCache: sock %s got %s => %s\r\n", $sock, $k, $v);
-      
-      return $val[$key];
+            $this->_debugprint(@sprintf("MemCache: sock %s got %s => %s\r\n", serialize($sock), $k, $v));
+
+      return @$val[$key];
    }
 
    // }}}
@@ -452,7 +452,7 @@ class memcached
       
       if ($this->_debug)
          foreach ($val as $k => $v)
-            printf("MemCache: got %s => %s\r\n", $k, $v);
+            $this->_debugprint(sprintf("MemCache: got %s => %s\r\n", $k, $v));
             
       return $val;
    }
@@ -737,13 +737,7 @@ class memcached
     */
    function _hashfunc ($key)
    {
-      $hash = 0;
-      for ($i=0; $i<strlen($key); $i++)
-      {
-         $hash = $hash*33 + ord($key[$i]);
-      }
-      
-      return $hash;
+      return crc32($key);
    }
 
    // }}}
@@ -813,14 +807,14 @@ class memcached
                   break;
                $offset += $n;
                $bneed -= $n;
-               $ret[$rkey] .= $data;
+               @$ret[$rkey] .= $data;
             }
             
             if ($offset != $len+2)
             {
                // Something is borked!
                if ($this->_debug)
-                  printf("Something is borked!  key %s expecting %d got %d length\n", $rkey, $len+2, $offset);
+                  $this->_debugprint(sprintf("Something is borked!  key %s expecting %d got %d length\n", $rkey, $len+2, $offset));
 
                unset($ret[$rkey]);
                $this->_close_sock($sock);
@@ -837,7 +831,7 @@ class memcached
 
          } else 
          {
-            print("Error parsing memcached response\n");
+            $this->_debugprint("Error parsing memcached response\n");
             return 0;
          }
       }
@@ -866,7 +860,7 @@ class memcached
       if (!is_resource($sock))
          return false;
          
-      $this->stats[$cmd]++;
+      @$this->stats[$cmd]++;
       
       $flags = 0;
       
@@ -875,7 +869,7 @@ class memcached
          $val = serialize($val);
          $flags |= MEMCACHE_SERIALIZED;
          if ($this->_debug)
-            printf("client: serializing data as it is not scalar\n");
+            $this->_debugprint(sprintf("client: serializing data as it is not scalar\n"));
       }
       
       $len = strlen($val);
@@ -889,7 +883,7 @@ class memcached
          if ($c_len < $len*(1 - COMPRESS_SAVINGS))
          {
             if ($this->_debug)
-               printf("client: compressing data; was %d bytes is now %d bytes\n", $len, $c_len);
+               $this->_debugprint(sprintf("client: compressing data; was %d bytes is now %d bytes\n", $len, $c_len));
             $val = $c_val;
             $len = $c_len;
             $flags |= MEMCACHE_COMPRESSED;
@@ -904,7 +898,7 @@ class memcached
       {
          if ($flags & MEMCACHE_COMPRESSED)
             $val = 'compressed data';
-         printf("MemCache: %s %s => %s (%s)\n", $cmd, $key, $val, $line);
+         $this->_debugprint(sprintf("MemCache: %s %s => %s (%s)\n", $cmd, $key, $val, $line));
       }
       if ($line == "STORED")
          return true;
@@ -944,6 +938,10 @@ class memcached
       return $this->_cache_sock[$host];
    }
 
+   function _debugprint($str){
+      print($str);
+   }
+
    // }}}
    // }}}
    // }}}