diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2008-08-15 01:29:47 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2008-08-15 01:29:47 +0200 |
commit | 370e83bb0dfd0c70de268c93bf07ad5ee0897192 (patch) | |
tree | 491674f4c242e4d6ba0d04eafa305174c35a3391 /includes/memcached-client.php | |
parent | f4debf0f12d0524d2b2427c55ea3f16b680fad97 (diff) |
Update auf 1.13.0
Diffstat (limited to 'includes/memcached-client.php')
-rw-r--r-- | includes/memcached-client.php | 79 |
1 files changed, 40 insertions, 39 deletions
diff --git a/includes/memcached-client.php b/includes/memcached-client.php index 2eddb908..6bd18387 100644 --- a/includes/memcached-client.php +++ b/includes/memcached-client.php @@ -57,47 +57,47 @@ * $val = $mc->get('key'); * * @author Ryan T. Dean <rtdean@cytherianage.net> - * @package memcached-client * @version 0.1.2 */ // {{{ requirements // }}} -// {{{ constants -// {{{ flags - -/** - * Flag: indicates data is serialized - */ -define("MEMCACHE_SERIALIZED", 1<<0); - -/** - * Flag: indicates data is compressed - */ -define("MEMCACHE_COMPRESSED", 1<<1); - -// }}} - -/** - * Minimum savings to store data compressed - */ -define("COMPRESSION_SAVINGS", 0.20); - -// }}} - // {{{ class memcached /** * memcached client class implemented using (p)fsockopen() * * @author Ryan T. Dean <rtdean@cytherianage.net> - * @addtogroup Cache + * @ingroup Cache */ class memcached { // {{{ properties // {{{ public + // {{{ constants + // {{{ flags + + /** + * Flag: indicates data is serialized + */ + const SERIALIZED = 1; + + /** + * Flag: indicates data is compressed + */ + const COMPRESSED = 2; + + // }}} + + /** + * Minimum savings to store data compressed + */ + const COMPRESSION_SAVINGS = 0.20; + + // }}} + + /** * Command statistics * @@ -152,7 +152,7 @@ class memcached /** * At how many bytes should we compress? * - * @var integer + * @var integer * @access private */ var $_compress_threshold; @@ -192,7 +192,7 @@ class memcached /** * Total # of bit buckets we have * - * @var integer + * @var integer * @access private */ var $_bucketcount; @@ -200,7 +200,7 @@ class memcached /** * # of total servers we have * - * @var integer + * @var integer * @access private */ var $_active; @@ -401,6 +401,10 @@ class memcached $fname = 'memcached::get'; wfProfileIn( $fname ); + if ( $this->_debug ) { + $this->_debugprint( "get($key)\n" ); + } + if (!$this->_active) { wfProfileOut( $fname ); return false; @@ -428,7 +432,7 @@ class memcached if ($this->_debug) foreach ($val as $k => $v) - $this->_debugprint(@sprintf("MemCache: sock %s got %s => %s\r\n", serialize($sock), $k, $v)); + $this->_debugprint(sprintf("MemCache: sock %s got %s\n", serialize($sock), $k)); wfProfileOut( $fname ); return @$val[$key]; @@ -452,7 +456,7 @@ class memcached $this->stats['get_multi']++; $sock_keys = array(); - + foreach ($keys as $key) { $sock = $this->get_sock($key); @@ -494,7 +498,7 @@ class memcached if ($this->_debug) foreach ($val as $k => $v) - $this->_debugprint(sprintf("MemCache: got %s => %s\r\n", $k, $v)); + $this->_debugprint(sprintf("MemCache: got %s\n", $k)); return $val; } @@ -904,12 +908,12 @@ class memcached return false; } - if ($this->_have_zlib && $flags & MEMCACHE_COMPRESSED) + if ($this->_have_zlib && $flags & memcached::COMPRESSED) $ret[$rkey] = gzuncompress($ret[$rkey]); $ret[$rkey] = rtrim($ret[$rkey]); - if ($flags & MEMCACHE_SERIALIZED) + if ($flags & memcached::SERIALIZED) $ret[$rkey] = unserialize($ret[$rkey]); } else @@ -950,7 +954,7 @@ class memcached if (!is_scalar($val)) { $val = serialize($val); - $flags |= MEMCACHE_SERIALIZED; + $flags |= memcached::SERIALIZED; if ($this->_debug) $this->_debugprint(sprintf("client: serializing data as it is not scalar\n")); } @@ -963,13 +967,13 @@ class memcached $c_val = gzcompress($val, 9); $c_len = strlen($c_val); - if ($c_len < $len*(1 - COMPRESSION_SAVINGS)) + if ($c_len < $len*(1 - memcached::COMPRESSION_SAVINGS)) { if ($this->_debug) $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; + $flags |= memcached::COMPRESSED; } } if (!$this->_safe_fwrite($sock, "$cmd $key $flags $exp $len\r\n$val\r\n")) @@ -979,9 +983,7 @@ class memcached if ($this->_debug) { - if ($flags & MEMCACHE_COMPRESSED) - $val = 'compressed data'; - $this->_debugprint(sprintf("MemCache: %s %s => %s (%s)\n", $cmd, $key, $val, $line)); + $this->_debugprint(sprintf("%s %s (%s)\n", $cmd, $key, $line)); } if ($line == "STORED") return true; @@ -1085,4 +1087,3 @@ class memcached // vim: sts=3 sw=3 et // }}} - |