* It's not nice to throw sql errors with invalid input
[lhc/web/wiklou.git] / includes / memcached-client.php
index b1ba778..2eddb90 100644 (file)
@@ -91,7 +91,7 @@ define("COMPRESSION_SAVINGS", 0.20);
  * memcached client class implemented using (p)fsockopen()
  *
  * @author  Ryan T. Dean <rtdean@cytherianage.net>
- * @package memcached-client
+ * @addtogroup Cache
  */
 class memcached
 {
@@ -152,7 +152,7 @@ class memcached
    /**
     * At how many bytes should we compress?
     *
-    * @var     interger
+    * @var     integer 
     * @access  private
     */
    var $_compress_threshold;
@@ -192,7 +192,7 @@ class memcached
    /**
     * Total # of bit buckets we have
     *
-    * @var     interger
+    * @var     integer 
     * @access  private
     */
    var $_bucketcount;
@@ -200,7 +200,7 @@ class memcached
    /**
     * # of total servers we have
     *
-    * @var     interger
+    * @var     integer 
     * @access  private
     */
    var $_active;
@@ -272,9 +272,9 @@ class memcached
     * Adds a key/value to the memcache server if one isn't already set with
     * that key
     *
-    * @param   string   $key     Key to set with data
-    * @param   mixed    $val     Value to store
-    * @param   interger $exp     (optional) Time to expire data at
+    * @param   string  $key     Key to set with data
+    * @param   mixed   $val     Value to store
+    * @param   integer $exp     (optional) Time to expire data at
     *
     * @return  boolean
     * @access  public
@@ -291,7 +291,7 @@ class memcached
     * Decriment a value stored on the memcache server
     *
     * @param   string   $key     Key to decriment
-    * @param   interger $amt     (optional) Amount to decriment
+    * @param   integer  $amt     (optional) Amount to decriment
     *
     * @return  mixed    FALSE on failure, value on success
     * @access  public
@@ -308,7 +308,7 @@ class memcached
     * Deletes a key from the server, optionally after $time
     *
     * @param   string   $key     Key to delete
-    * @param   interger $time    (optional) How long to wait before deleting
+    * @param   integer  $time    (optional) How long to wait before deleting
     *
     * @return  boolean  TRUE on success, FALSE on failure
     * @access  public
@@ -451,7 +451,8 @@ class memcached
          return false;
 
       $this->stats['get_multi']++;
-
+      $sock_keys = array();
+      
       foreach ($keys as $key)
       {
          $sock = $this->get_sock($key);
@@ -505,9 +506,9 @@ class memcached
     * Increments $key (optionally) by $amt
     *
     * @param   string   $key     Key to increment
-    * @param   interger $amt     (optional) amount to increment
+    * @param   integer  $amt     (optional) amount to increment
     *
-    * @return  interger New key value?
+    * @return  integer  New key value?
     * @access  public
     */
    function incr ($key, $amt=1)
@@ -523,7 +524,7 @@ class memcached
     *
     * @param   string   $key     Key to set value as
     * @param   mixed    $value   Value to store
-    * @param   interger $exp     (optional) Experiation time
+    * @param   integer  $exp     (optional) Experiation time
     *
     * @return  boolean
     * @access  public
@@ -581,7 +582,7 @@ class memcached
     *
     * @param   string   $key     Key to set value as
     * @param   mixed    $value   Value to set
-    * @param   interger $exp     (optional) Experiation time
+    * @param   integer  $exp     (optional) Experiation time
     *
     * @return  boolean  TRUE on success
     * @access  public
@@ -597,7 +598,7 @@ class memcached
    /**
     * Sets the compression threshold
     *
-    * @param   interger $thresh  Threshold to compress if larger than
+    * @param   integer  $thresh  Threshold to compress if larger than
     *
     * @access  public
     */
@@ -686,7 +687,7 @@ class memcached
    /**
     * Connects $sock to $host, timing out after $timeout
     *
-    * @param   interger $sock    Socket to connect
+    * @param   integer  $sock    Socket to connect
     * @param   string   $host    Host:IP to connect to
     *
     * @return  boolean
@@ -697,6 +698,7 @@ class memcached
       list ($ip, $port) = explode(":", $host);
       $sock = false;
       $timeout = $this->_connect_timeout;
+      $errno = $errstr = null;
       for ($i = 0; !$sock && $i < $this->_connect_attempts; $i++) {
          if ($i > 0) {
             # Sleep until the timeout, in case it failed fast
@@ -740,7 +742,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]);
@@ -805,11 +807,11 @@ class memcached
    // {{{ _hashfunc()
 
    /**
-    * Creates a hash interger based on the $key
+    * Creates a hash integer  based on the $key
     *
     * @param   string   $key     Key to hash
     *
-    * @return  interger Hash value
+    * @return  integer  Hash value
     * @access  private
     */
    function _hashfunc ($key)
@@ -828,9 +830,9 @@ class memcached
     *
     * @param   string   $cmd     Command to perform
     * @param   string   $key     Key to perform it on
-    * @param   interger $amt     Amount to adjust
+    * @param   integer  $amt     Amount to adjust
     *
-    * @return  interger    New value of $key
+    * @return  integer     New value of $key
     * @access  private
     */
    function _incrdecr ($cmd, $key, $amt=1)
@@ -849,6 +851,7 @@ class memcached
 
       stream_set_timeout($sock, 1, 0);
       $line = fgets($sock);
+      $match = array();
       if (!preg_match('/^(\d+)/', $line, $match))
          return null;
       return $match[1];
@@ -926,7 +929,7 @@ class memcached
     * @param   string   $cmd     Command to perform
     * @param   string   $key     Key to act on
     * @param   mixed    $val     What we need to store
-    * @param   interger $exp     When it should expire
+    * @param   integer  $exp     When it should expire
     *
     * @return  boolean
     * @access  private
@@ -1001,8 +1004,9 @@ class memcached
       if (isset($this->_cache_sock[$host]))
          return $this->_cache_sock[$host];
 
+      $sock = null;
       $now = time();
-      list ($ip, $port) = explode (":", $host);
+      list ($ip, /* $port */) = explode (":", $host);
       if (isset($this->_host_dead[$host]) && $this->_host_dead[$host] > $now ||
           isset($this->_host_dead[$ip]) && $this->_host_dead[$ip] > $now)
          return null;
@@ -1081,4 +1085,4 @@ class memcached
 // vim: sts=3 sw=3 et
 
 // }}}
-?>
+