diff --git a/Cache/AntiDogPileMemcache.php b/Cache/AntiDogPileMemcache.php index 4b5a6fd..db5f793 100644 --- a/Cache/AntiDogPileMemcache.php +++ b/Cache/AntiDogPileMemcache.php @@ -2,7 +2,7 @@ namespace Lsw\MemcacheBundle\Cache; /** - * Class to encapsulate PHP Memcached object to avoid the "Dog Pile" effect + * Class to encapsulate PHP Memcache object to avoid the "Dog Pile" effect */ class AntiDogPileMemcache extends LoggingMemcache { @@ -21,8 +21,7 @@ class AntiDogPileMemcache extends LoggingMemcache */ public function getAdp($key) { - $cas=0; - $value = $this->get($key, null, $cas); + $value = $this->get($key, $flags, $cas); if ($value===false) { return false; } @@ -32,8 +31,7 @@ public function getAdp($key) $time = time(); if ($time>$exp) { $value = implode('|', array($time+$ttl, $ttl, json_encode($val))); - $result = $this->cas($cas, $key, $value, 0); - + $result = $this->cas($key, $value, $flags, 0, $cas); if ($result) { return false; } @@ -59,7 +57,7 @@ public function setAdp($key, $value, $ttl=0) } $time = time(); $value = implode('|', array($time+$ttl, $ttl, json_encode($value))); - $result = $this->set($key, $value, 0); + $result = $this->set($key, $value); return $result; } diff --git a/Cache/LoggingMemcache.php b/Cache/LoggingMemcache.php index 55961a1..651d495 100644 --- a/Cache/LoggingMemcache.php +++ b/Cache/LoggingMemcache.php @@ -1,21 +1,14 @@ getVersion()=='1.0.2') { - class LoggingMemcache extends \Memcached implements MemcacheInterface, LoggingMemcacheInterface { - public function __construct($logging, $persistent_id = '') { +$extension = new \ReflectionExtension('memcache'); +if ($extension->getVersion()=='3.0.8') { + class LoggingMemcache extends \MemcachePool implements MemcacheInterface, LoggingMemcacheInterface { + public function __construct($logging) { $this->calls = array(); $this->logging = $logging; - if ($persistent_id) { - $this->initialize = count($this->getServerList())==0; - } else { - $this->initialize = true; - } - parent::__construct($persistent_id); } private $calls; - private $initialize; private $logging; public function getLoggedCalls() { return $this->calls; @@ -25,2423 +18,307 @@ private function logCall($start, $result) { $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); return $result; } - public function get( $key, $cache_cb = null, &$cas_token = null ) { - if (!$this->logging) return parent::get($key,$cache_cb,$cas_token); - $start = microtime(true); - $name = 'get'; - $arguments = array($key,$cache_cb,$cas_token); - $result = parent::get($key,$cache_cb,$cas_token); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getByKey( $server_key, $key, $cache_cb = null, &$cas_token = null ) { - if (!$this->logging) return parent::getByKey($server_key,$key,$cache_cb,$cas_token); - $start = microtime(true); - $name = 'getByKey'; - $arguments = array($server_key,$key,$cache_cb,$cas_token); - $result = parent::getByKey($server_key,$key,$cache_cb,$cas_token); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getMulti( array $keys, &$cas_tokens = null, $flags = 0 ) { - if (!$this->logging) return parent::getMulti($keys,$cas_tokens,$flags); - $start = microtime(true); - $name = 'getMulti'; - $arguments = array($keys,$cas_tokens,$flags); - $result = parent::getMulti($keys,$cas_tokens,$flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getMultiByKey( $server_key, array $keys, &$cas_tokens = null, $flags = 0 ) { - if (!$this->logging) return parent::getMultiByKey($server_key,$keys,$cas_tokens,$flags); - $start = microtime(true); - $name = 'getMultiByKey'; - $arguments = array($server_key,$keys,$cas_tokens,$flags); - $result = parent::getMultiByKey($server_key,$keys,$cas_tokens,$flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getDelayed( array $keys, $with_cas = null, $value_cb = null ) { - if (!$this->logging) return parent::getDelayed($keys,$with_cas,$value_cb); - $start = microtime(true); - $name = 'getDelayed'; - $arguments = array($keys,$with_cas,$value_cb); - $result = parent::getDelayed($keys,$with_cas,$value_cb); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getDelayedByKey( $server_key, array $keys, $with_cas = null, $value_cb = null ) { - if (!$this->logging) return parent::getDelayedByKey($server_key,$keys,$with_cas,$value_cb); - $start = microtime(true); - $name = 'getDelayedByKey'; - $arguments = array($server_key,$keys,$with_cas,$value_cb); - $result = parent::getDelayedByKey($server_key,$keys,$with_cas,$value_cb); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function fetch( ) { - if (!$this->logging) return parent::fetch(); - $start = microtime(true); - $name = 'fetch'; - $arguments = array(); - $result = parent::fetch(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function fetchAll( ) { - if (!$this->logging) return parent::fetchAll(); - $start = microtime(true); - $name = 'fetchAll'; - $arguments = array(); - $result = parent::fetchAll(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function set( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::set($key,$value,$expiration); - $start = microtime(true); - $name = 'set'; - $arguments = array($key,$value,$expiration); - $result = parent::set($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::setByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'setByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::setByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setMulti( array $items, $expiration = 0 ) { - if (!$this->logging) return parent::setMulti($items,$expiration); - $start = microtime(true); - $name = 'setMulti'; - $arguments = array($items,$expiration); - $result = parent::setMulti($items,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setMultiByKey( $server_key, array $items, $expiration = 0 ) { - if (!$this->logging) return parent::setMultiByKey($server_key,$items,$expiration); - $start = microtime(true); - $name = 'setMultiByKey'; - $arguments = array($server_key,$items,$expiration); - $result = parent::setMultiByKey($server_key,$items,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function cas( $token, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::cas($token,$key,$value,$expiration); - $start = microtime(true); - $name = 'cas'; - $arguments = array($token,$key,$value,$expiration); - $result = parent::cas($token,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function casByKey( $token, $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::casByKey($token,$server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'casByKey'; - $arguments = array($token,$server_key,$key,$value,$expiration); - $result = parent::casByKey($token,$server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function add( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::add($key,$value,$expiration); - $start = microtime(true); - $name = 'add'; - $arguments = array($key,$value,$expiration); - $result = parent::add($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function addByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::addByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'addByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::addByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function append( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::append($key,$value,$expiration); - $start = microtime(true); - $name = 'append'; - $arguments = array($key,$value,$expiration); - $result = parent::append($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function appendByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::appendByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'appendByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::appendByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function prepend( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::prepend($key,$value,$expiration); - $start = microtime(true); - $name = 'prepend'; - $arguments = array($key,$value,$expiration); - $result = parent::prepend($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function prependByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::prependByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'prependByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::prependByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function replace( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::replace($key,$value,$expiration); - $start = microtime(true); - $name = 'replace'; - $arguments = array($key,$value,$expiration); - $result = parent::replace($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function replaceByKey( $serve_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::replaceByKey($serve_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'replaceByKey'; - $arguments = array($serve_key,$key,$value,$expiration); - $result = parent::replaceByKey($serve_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function delete( $key, $time = 0 ) { - if (!$this->logging) return parent::delete($key,$time); - $start = microtime(true); - $name = 'delete'; - $arguments = array($key,$time); - $result = parent::delete($key,$time); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function deleteByKey( $server_key, $key, $time = 0 ) { - if (!$this->logging) return parent::deleteByKey($server_key,$key,$time); - $start = microtime(true); - $name = 'deleteByKey'; - $arguments = array($server_key,$key,$time); - $result = parent::deleteByKey($server_key,$key,$time); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function increment( $key, $offset = 1) { - if (!$this->logging) return parent::increment($key,$offset); - $start = microtime(true); - $name = 'increment'; - $arguments = array($key,$offset); - $result = parent::increment($key,$offset); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function decrement( $key, $offset = 1) { - if (!$this->logging) return parent::decrement($key,$offset); - $start = microtime(true); - $name = 'decrement'; - $arguments = array($key,$offset); - $result = parent::decrement($key,$offset); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getOption( $option ) { - if (!$this->logging) return parent::getOption($option); - $start = microtime(true); - $name = 'getOption'; - $arguments = array($option); - $result = parent::getOption($option); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setOption( $option, $value ) { - if (!$this->logging) return parent::setOption($option,$value); - $start = microtime(true); - $name = 'setOption'; - $arguments = array($option,$value); - $result = parent::setOption($option,$value); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function addServer( $host, $port, $weight = 0 ) { - if (!$this->logging) return parent::addServer($host,$port,$weight); - $start = microtime(true); - $name = 'addServer'; - $arguments = array($host,$port,$weight); - $result = parent::addServer($host,$port,$weight); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function addServers( array $servers ) { - if (!$this->logging) return parent::addServers($servers); - $start = microtime(true); - $name = 'addServers'; - $arguments = array($servers); - $result = parent::addServers($servers); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getServerList( ) { - if (!$this->logging) return parent::getServerList(); - $start = microtime(true); - $name = 'getServerList'; - $arguments = array(); - $result = parent::getServerList(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getServerByKey( $server_key ) { - if (!$this->logging) return parent::getServerByKey($server_key); - $start = microtime(true); - $name = 'getServerByKey'; - $arguments = array($server_key); - $result = parent::getServerByKey($server_key); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function flush( $delay = 0 ) { - if (!$this->logging) return parent::flush($delay); - $start = microtime(true); - $name = 'flush'; - $arguments = array($delay); - $result = parent::flush($delay); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getStats( ) { - if (!$this->logging) return parent::getStats(); - $start = microtime(true); - $name = 'getStats'; - $arguments = array(); - $result = parent::getStats(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getResultCode( ) { - if (!$this->logging) return parent::getResultCode(); - $start = microtime(true); - $name = 'getResultCode'; - $arguments = array(); - $result = parent::getResultCode(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getResultMessage( ) { - if (!$this->logging) return parent::getResultMessage(); - $start = microtime(true); - $name = 'getResultMessage'; - $arguments = array(); - $result = parent::getResultMessage(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - } -} else if ($extension->getVersion()=='2.0.1') { - class LoggingMemcache extends \Memcached implements MemcacheInterface, LoggingMemcacheInterface { - public function __construct($logging, $persistent_id = '') { - $this->calls = array(); - $this->logging = $logging; - if ($persistent_id) { - $this->initialize = count($this->getServerList())==0; - } else { - $this->initialize = true; + public function setFailureCallback($failureCallback) { + if ($this->logging) { + $start = microtime(true); + $name = 'setFailureCallback'; + $arguments = array($failureCallback); + } + list($_failureCallback) = array($failureCallback); + $result = parent::setFailureCallback($_failureCallback); + list($failureCallback) = array($_failureCallback); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); } - parent::__construct($persistent_id); - } - private $calls; - private $initialize; - private $logging; - public function getLoggedCalls() { - return $this->calls; - } - private function logCall($start, $result) { - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function get( $key, $cache_cb = null, &$cas_token = null ) { - if (!$this->logging) return parent::get($key,$cache_cb,$cas_token); - $start = microtime(true); - $name = 'get'; - $arguments = array($key,$cache_cb,$cas_token); - $result = parent::get($key,$cache_cb,$cas_token); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getByKey( $server_key, $key, $cache_cb = null, &$cas_token = null ) { - if (!$this->logging) return parent::getByKey($server_key,$key,$cache_cb,$cas_token); - $start = microtime(true); - $name = 'getByKey'; - $arguments = array($server_key,$key,$cache_cb,$cas_token); - $result = parent::getByKey($server_key,$key,$cache_cb,$cas_token); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getMulti( array $keys, &$cas_tokens = null, $flags = null ) { - if (!$this->logging) return parent::getMulti($keys,$cas_tokens,$flags); - $start = microtime(true); - $name = 'getMulti'; - $arguments = array($keys,$cas_tokens,$flags); - $result = parent::getMulti($keys,$cas_tokens,$flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getMultiByKey( $server_key, array $keys, &$cas_tokens = null, $flags = null ) { - if (!$this->logging) return parent::getMultiByKey($server_key,$keys,$cas_tokens,$flags); - $start = microtime(true); - $name = 'getMultiByKey'; - $arguments = array($server_key,$keys,$cas_tokens,$flags); - $result = parent::getMultiByKey($server_key,$keys,$cas_tokens,$flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getDelayed( array $keys, $with_cas = null, $value_cb = null ) { - if (!$this->logging) return parent::getDelayed($keys,$with_cas,$value_cb); - $start = microtime(true); - $name = 'getDelayed'; - $arguments = array($keys,$with_cas,$value_cb); - $result = parent::getDelayed($keys,$with_cas,$value_cb); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getDelayedByKey( $server_key, array $keys, $with_cas = null, $value_cb = null ) { - if (!$this->logging) return parent::getDelayedByKey($server_key,$keys,$with_cas,$value_cb); - $start = microtime(true); - $name = 'getDelayedByKey'; - $arguments = array($server_key,$keys,$with_cas,$value_cb); - $result = parent::getDelayedByKey($server_key,$keys,$with_cas,$value_cb); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); return $result; } - public function fetch( ) { - if (!$this->logging) return parent::fetch(); - $start = microtime(true); - $name = 'fetch'; - $arguments = array(); - $result = parent::fetch(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function getServerStatus($host,$port=11211) { + if ($this->logging) { + $start = microtime(true); + $name = 'getServerStatus'; + $arguments = array($host,$port); + } + list($_host,$_port) = array($host,$port); + $result = parent::getServerStatus($_host,$_port); + list($host,$port) = array($_host,$_port); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function fetchAll( ) { - if (!$this->logging) return parent::fetchAll(); - $start = microtime(true); - $name = 'fetchAll'; - $arguments = array(); - $result = parent::fetchAll(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function getVersion() { + if ($this->logging) { + $start = microtime(true); + $name = 'getVersion'; + $arguments = array(); + } + list() = array(); + $result = parent::getVersion(); + list() = array(); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function set( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::set($key,$value,$expiration); - $start = microtime(true); - $name = 'set'; - $arguments = array($key,$value,$expiration); - $result = parent::set($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function add($key,$var=null,$flag=0,$exptime=0) { + if ($this->logging) { + $start = microtime(true); + $name = 'add'; + $arguments = array($key,$var,$flag,$exptime); + } + list($_key,$_var,$_flag,$_exptime) = array($key,$var,$flag,$exptime); + $result = parent::add($_key,$_var,$_flag,$_exptime); + list($key,$var,$flag,$exptime) = array($_key,$_var,$_flag,$_exptime); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function touch( $key, $expiration = 0 ) { - if (!$this->logging) return parent::touch($key,$expiration); - $start = microtime(true); - $name = 'touch'; - $arguments = array($key,$expiration); - $result = parent::touch($key,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function set($key,$var=null,$flag=0,$exptime=0) { + if ($this->logging) { + $start = microtime(true); + $name = 'set'; + $arguments = array($key,$var,$flag,$exptime); + } + list($_key,$_var,$_flag,$_exptime) = array($key,$var,$flag,$exptime); + $result = parent::set($_key,$_var,$_flag,$_exptime); + list($key,$var,$flag,$exptime) = array($_key,$_var,$_flag,$_exptime); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function touchbyKey( $server_key, $key, $expiration = 0 ) { - if (!$this->logging) return parent::touchbyKey($server_key,$key,$expiration); - $start = microtime(true); - $name = 'touchbyKey'; - $arguments = array($server_key,$key,$expiration); - $result = parent::touchbyKey($server_key,$key,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function replace($key,$var=null,$flag=0,$exptime=0) { + if ($this->logging) { + $start = microtime(true); + $name = 'replace'; + $arguments = array($key,$var,$flag,$exptime); + } + list($_key,$_var,$_flag,$_exptime) = array($key,$var,$flag,$exptime); + $result = parent::replace($_key,$_var,$_flag,$_exptime); + list($key,$var,$flag,$exptime) = array($_key,$_var,$_flag,$_exptime); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function setByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::setByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'setByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::setByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function cas($key,$var=null,$flag=0,$exptime=0,$cas=0) { + if ($this->logging) { + $start = microtime(true); + $name = 'cas'; + $arguments = array($key,$var,$flag,$exptime,$cas); + } + list($_key,$_var,$_flag,$_exptime,$_cas) = array($key,$var,$flag,$exptime,$cas); + $result = parent::cas($_key,$_var,$_flag,$_exptime,$_cas); + list($key,$var,$flag,$exptime,$cas) = array($_key,$_var,$_flag,$_exptime,$_cas); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function setMulti( array $items, $expiration = 0 ) { - if (!$this->logging) return parent::setMulti($items,$expiration); - $start = microtime(true); - $name = 'setMulti'; - $arguments = array($items,$expiration); - $result = parent::setMulti($items,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function prepend($key,$var=null,$flag=0,$exptime=0) { + if ($this->logging) { + $start = microtime(true); + $name = 'prepend'; + $arguments = array($key,$var,$flag,$exptime); + } + list($_key,$_var,$_flag,$_exptime) = array($key,$var,$flag,$exptime); + $result = parent::prepend($_key,$_var,$_flag,$_exptime); + list($key,$var,$flag,$exptime) = array($_key,$_var,$_flag,$_exptime); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function setMultiByKey( $server_key, array $items, $expiration = 0 ) { - if (!$this->logging) return parent::setMultiByKey($server_key,$items,$expiration); - $start = microtime(true); - $name = 'setMultiByKey'; - $arguments = array($server_key,$items,$expiration); - $result = parent::setMultiByKey($server_key,$items,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function get($key,&$flags=null,&$cas=null) { + if ($this->logging) { + $start = microtime(true); + $name = 'get'; + $arguments = array($key,$flags,$cas); + } + list($_key,$_flags,$_cas) = array($key,$flags,$cas); + $result = parent::get($_key,$_flags,$_cas); + list($key,$flags,$cas) = array($_key,$_flags,$_cas); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function cas( $token, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::cas($token,$key,$value,$expiration); - $start = microtime(true); - $name = 'cas'; - $arguments = array($token,$key,$value,$expiration); - $result = parent::cas($token,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function getStats($type='',$slabid=0,$limit=100) { + if ($this->logging) { + $start = microtime(true); + $name = 'getStats'; + $arguments = array($type,$slabid,$limit); + } + list($_type,$_slabid,$_limit) = array($type,$slabid,$limit); + $result = parent::getStats($_type,$_slabid,$_limit); + list($type,$slabid,$limit) = array($_type,$_slabid,$_limit); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function casByKey( $token, $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::casByKey($token,$server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'casByKey'; - $arguments = array($token,$server_key,$key,$value,$expiration); - $result = parent::casByKey($token,$server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function getExtendedStats($type='',$slabid=0,$limit=100) { + if ($this->logging) { + $start = microtime(true); + $name = 'getExtendedStats'; + $arguments = array($type,$slabid,$limit); + } + list($_type,$_slabid,$_limit) = array($type,$slabid,$limit); + $result = parent::getExtendedStats($_type,$_slabid,$_limit); + list($type,$slabid,$limit) = array($_type,$_slabid,$_limit); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function add( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::add($key,$value,$expiration); - $start = microtime(true); - $name = 'add'; - $arguments = array($key,$value,$expiration); - $result = parent::add($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function setCompressThreshold($threshold,$minSavings=0.2) { + if ($this->logging) { + $start = microtime(true); + $name = 'setCompressThreshold'; + $arguments = array($threshold,$minSavings); + } + list($_threshold,$_minSavings) = array($threshold,$minSavings); + $result = parent::setCompressThreshold($_threshold,$_minSavings); + list($threshold,$minSavings) = array($_threshold,$_minSavings); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function addByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::addByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'addByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::addByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function delete($key,$exptime=0) { + if ($this->logging) { + $start = microtime(true); + $name = 'delete'; + $arguments = array($key,$exptime); + } + list($_key,$_exptime) = array($key,$exptime); + $result = parent::delete($_key,$_exptime); + list($key,$exptime) = array($_key,$_exptime); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function append( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::append($key,$value,$expiration); - $start = microtime(true); - $name = 'append'; - $arguments = array($key,$value,$expiration); - $result = parent::append($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function increment($key,$value=1,$defval=0,$exptime=0) { + if ($this->logging) { + $start = microtime(true); + $name = 'increment'; + $arguments = array($key,$value,$defval,$exptime); + } + list($_key,$_value,$_defval,$_exptime) = array($key,$value,$defval,$exptime); + $result = parent::increment($_key,$_value,$_defval,$_exptime); + list($key,$value,$defval,$exptime) = array($_key,$_value,$_defval,$_exptime); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function appendByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::appendByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'appendByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::appendByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function decrement($key,$value=1,$defval=0,$exptime=0) { + if ($this->logging) { + $start = microtime(true); + $name = 'decrement'; + $arguments = array($key,$value,$defval,$exptime); + } + list($_key,$_value,$_defval,$_exptime) = array($key,$value,$defval,$exptime); + $result = parent::decrement($_key,$_value,$_defval,$_exptime); + list($key,$value,$defval,$exptime) = array($_key,$_value,$_defval,$_exptime); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function prepend( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::prepend($key,$value,$expiration); - $start = microtime(true); - $name = 'prepend'; - $arguments = array($key,$value,$expiration); - $result = parent::prepend($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function close() { + if ($this->logging) { + $start = microtime(true); + $name = 'close'; + $arguments = array(); + } + list() = array(); + $result = parent::close(); + list() = array(); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function prependByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::prependByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'prependByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::prependByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function flush($delay=0) { + if ($this->logging) { + $start = microtime(true); + $name = 'flush'; + $arguments = array($delay); + } + list($_delay) = array($delay); + $result = parent::flush($_delay); + list($delay) = array($_delay); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function replace( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::replace($key,$value,$expiration); - $start = microtime(true); - $name = 'replace'; - $arguments = array($key,$value,$expiration); - $result = parent::replace($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function addServer($host,$tcpPort=11211,$udpPort=0,$persistent=true,$weight=1,$timeout=1,$retryInterval=15,$status=true) { + if ($this->logging) { + $start = microtime(true); + $name = 'addServer'; + $arguments = array($host,$tcpPort,$udpPort,$persistent,$weight,$timeout,$retryInterval,$status); + } + list($_host,$_tcpPort,$_udpPort,$_persistent,$_weight,$_timeout,$_retryInterval,$_status) = array($host,$tcpPort,$udpPort,$persistent,$weight,$timeout,$retryInterval,$status); + $result = parent::addServer($_host,$_tcpPort,$_udpPort,$_persistent,$_weight,$_timeout,$_retryInterval,$_status); + list($host,$tcpPort,$udpPort,$persistent,$weight,$timeout,$retryInterval,$status) = array($_host,$_tcpPort,$_udpPort,$_persistent,$_weight,$_timeout,$_retryInterval,$_status); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function replaceByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::replaceByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'replaceByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::replaceByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + public function connect($host,$tcpPort=11211,$udpPort=0,$persistent=true,$weight=1,$timeout=1,$retryInterval=15) { + if ($this->logging) { + $start = microtime(true); + $name = 'connect'; + $arguments = array($host,$tcpPort,$udpPort,$persistent,$weight,$timeout,$retryInterval); + } + list($_host,$_tcpPort,$_udpPort,$_persistent,$_weight,$_timeout,$_retryInterval) = array($host,$tcpPort,$udpPort,$persistent,$weight,$timeout,$retryInterval); + $result = parent::connect($_host,$_tcpPort,$_udpPort,$_persistent,$_weight,$_timeout,$_retryInterval); + list($host,$tcpPort,$udpPort,$persistent,$weight,$timeout,$retryInterval) = array($_host,$_tcpPort,$_udpPort,$_persistent,$_weight,$_timeout,$_retryInterval); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return $result; } - public function delete( $key, $time = 0 ) { - if (!$this->logging) return parent::delete($key,$time); - $start = microtime(true); - $name = 'delete'; - $arguments = array($key,$time); - $result = parent::delete($key,$time); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function deleteByKey( $server_key, $key, $time = 0 ) { - if (!$this->logging) return parent::deleteByKey($server_key,$key,$time); - $start = microtime(true); - $name = 'deleteByKey'; - $arguments = array($server_key,$key,$time); - $result = parent::deleteByKey($server_key,$key,$time); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function deleteMulti( $keys, $expiration = 0 ) { - if (!$this->logging) return parent::deleteMulti($keys,$expiration); - $start = microtime(true); - $name = 'deleteMulti'; - $arguments = array($keys,$expiration); - $result = parent::deleteMulti($keys,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function deleteMultiByKey( $server_key, $keys, $expiration = 0 ) { - if (!$this->logging) return parent::deleteMultiByKey($server_key,$keys,$expiration); - $start = microtime(true); - $name = 'deleteMultiByKey'; - $arguments = array($server_key,$keys,$expiration); - $result = parent::deleteMultiByKey($server_key,$keys,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function increment( $key, $offset = 1, $initial_value = 0, $expiry = 0 ) { - if (!$this->logging) return parent::increment($key,$offset,$initial_value,$expiry); - $start = microtime(true); - $name = 'increment'; - $arguments = array($key,$offset,$initial_value,$expiry); - $result = parent::increment($key,$offset,$initial_value,$expiry); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function incrementByKey( $server_key, $key, $offset = 1, $initial_value = 0, $expiry = 0 ) { - if (!$this->logging) return parent::incrementByKey($server_key,$key,$offset,$initial_value,$expiry); - $start = microtime(true); - $name = 'incrementByKey'; - $arguments = array($server_key,$key,$offset,$initial_value,$expiry); - $result = parent::incrementByKey($server_key,$key,$offset,$initial_value,$expiry); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function decrement( $key, $offset = 1, $initial_value = 0, $expiry = 0 ) { - if (!$this->logging) return parent::decrement($key,$offset,$initial_value,$expiry); - $start = microtime(true); - $name = 'decrement'; - $arguments = array($key,$offset,$initial_value,$expiry); - $result = parent::decrement($key,$offset,$initial_value,$expiry); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function decrementByKey( $server_key, $key, $offset = 1, $initial_value = 0, $expiry = 0 ) { - if (!$this->logging) return parent::decrementByKey($server_key,$key,$offset,$initial_value,$expiry); - $start = microtime(true); - $name = 'decrementByKey'; - $arguments = array($server_key,$key,$offset,$initial_value,$expiry); - $result = parent::decrementByKey($server_key,$key,$offset,$initial_value,$expiry); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getOption( $option ) { - if (!$this->logging) return parent::getOption($option); - $start = microtime(true); - $name = 'getOption'; - $arguments = array($option); - $result = parent::getOption($option); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setOption( $option, $value ) { - if (!$this->logging) return parent::setOption($option,$value); - $start = microtime(true); - $name = 'setOption'; - $arguments = array($option,$value); - $result = parent::setOption($option,$value); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setOptions( $options ) { - if (!$this->logging) return parent::setOptions($options); - $start = microtime(true); - $name = 'setOptions'; - $arguments = array($options); - $result = parent::setOptions($options); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function addServer( $host, $port, $weight = 0 ) { - if (!$this->logging) return parent::addServer($host,$port,$weight); - $start = microtime(true); - $name = 'addServer'; - $arguments = array($host,$port,$weight); - $result = parent::addServer($host,$port,$weight); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function addServers( array $servers ) { - if (!$this->logging) return parent::addServers($servers); - $start = microtime(true); - $name = 'addServers'; - $arguments = array($servers); - $result = parent::addServers($servers); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getServerList( ) { - if (!$this->logging) return parent::getServerList(); - $start = microtime(true); - $name = 'getServerList'; - $arguments = array(); - $result = parent::getServerList(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getServerByKey( $server_key ) { - if (!$this->logging) return parent::getServerByKey($server_key); - $start = microtime(true); - $name = 'getServerByKey'; - $arguments = array($server_key); - $result = parent::getServerByKey($server_key); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function flush( $delay = 0 ) { - if (!$this->logging) return parent::flush($delay); - $start = microtime(true); - $name = 'flush'; - $arguments = array($delay); - $result = parent::flush($delay); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getStats( ) { - if (!$this->logging) return parent::getStats(); - $start = microtime(true); - $name = 'getStats'; - $arguments = array(); - $result = parent::getStats(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getVersion( ) { - if (!$this->logging) return parent::getVersion(); - $start = microtime(true); - $name = 'getVersion'; - $arguments = array(); - $result = parent::getVersion(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getResultCode( ) { - if (!$this->logging) return parent::getResultCode(); - $start = microtime(true); - $name = 'getResultCode'; - $arguments = array(); - $result = parent::getResultCode(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getResultMessage( ) { - if (!$this->logging) return parent::getResultMessage(); - $start = microtime(true); - $name = 'getResultMessage'; - $arguments = array(); - $result = parent::getResultMessage(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function isPersistent( ) { - if (!$this->logging) return parent::isPersistent(); - $start = microtime(true); - $name = 'isPersistent'; - $arguments = array(); - $result = parent::isPersistent(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function isPristine( ) { - if (!$this->logging) return parent::isPristine(); - $start = microtime(true); - $name = 'isPristine'; - $arguments = array(); - $result = parent::isPristine(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - } -} else if ($extension->getVersion()=='2.1.0') { - class LoggingMemcache extends \Memcached implements MemcacheInterface, LoggingMemcacheInterface { - public function __construct($logging, $persistent_id = '') { - $this->calls = array(); - $this->logging = $logging; - if ($persistent_id) { - $this->initialize = count($this->getServerList())==0; - } else { - $this->initialize = true; - } - parent::__construct($persistent_id); - } - private $calls; - private $initialize; - private $logging; - public function getLoggedCalls() { - return $this->calls; - } - private function logCall($start, $result) { - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function get( $key, $cache_cb = null, &$cas_token = null ) { - if (!$this->logging) return parent::get($key,$cache_cb,$cas_token); - $start = microtime(true); - $name = 'get'; - $arguments = array($key,$cache_cb,$cas_token); - $result = parent::get($key,$cache_cb,$cas_token); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getByKey( $server_key, $key, $cache_cb = null, &$cas_token = null ) { - if (!$this->logging) return parent::getByKey($server_key,$key,$cache_cb,$cas_token); - $start = microtime(true); - $name = 'getByKey'; - $arguments = array($server_key,$key,$cache_cb,$cas_token); - $result = parent::getByKey($server_key,$key,$cache_cb,$cas_token); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getMulti( array $keys, &$cas_tokens = null, $flags = null ) { - if (!$this->logging) return parent::getMulti($keys,$cas_tokens,$flags); - $start = microtime(true); - $name = 'getMulti'; - $arguments = array($keys,$cas_tokens,$flags); - $result = parent::getMulti($keys,$cas_tokens,$flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getMultiByKey( $server_key, array $keys, &$cas_tokens = null, $flags = null ) { - if (!$this->logging) return parent::getMultiByKey($server_key,$keys,$cas_tokens,$flags); - $start = microtime(true); - $name = 'getMultiByKey'; - $arguments = array($server_key,$keys,$cas_tokens,$flags); - $result = parent::getMultiByKey($server_key,$keys,$cas_tokens,$flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getDelayed( array $keys, $with_cas = null, $value_cb = null ) { - if (!$this->logging) return parent::getDelayed($keys,$with_cas,$value_cb); - $start = microtime(true); - $name = 'getDelayed'; - $arguments = array($keys,$with_cas,$value_cb); - $result = parent::getDelayed($keys,$with_cas,$value_cb); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getDelayedByKey( $server_key, array $keys, $with_cas = null, $value_cb = null ) { - if (!$this->logging) return parent::getDelayedByKey($server_key,$keys,$with_cas,$value_cb); - $start = microtime(true); - $name = 'getDelayedByKey'; - $arguments = array($server_key,$keys,$with_cas,$value_cb); - $result = parent::getDelayedByKey($server_key,$keys,$with_cas,$value_cb); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function fetch( ) { - if (!$this->logging) return parent::fetch(); - $start = microtime(true); - $name = 'fetch'; - $arguments = array(); - $result = parent::fetch(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function fetchAll( ) { - if (!$this->logging) return parent::fetchAll(); - $start = microtime(true); - $name = 'fetchAll'; - $arguments = array(); - $result = parent::fetchAll(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function set( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::set($key,$value,$expiration); - $start = microtime(true); - $name = 'set'; - $arguments = array($key,$value,$expiration); - $result = parent::set($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function touch( $key, $expiration = 0 ) { - if (!$this->logging) return parent::touch($key,$expiration); - $start = microtime(true); - $name = 'touch'; - $arguments = array($key,$expiration); - $result = parent::touch($key,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function touchbyKey( $server_key, $key, $expiration = 0 ) { - if (!$this->logging) return parent::touchbyKey($server_key,$key,$expiration); - $start = microtime(true); - $name = 'touchbyKey'; - $arguments = array($server_key,$key,$expiration); - $result = parent::touchbyKey($server_key,$key,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::setByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'setByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::setByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setMulti( array $items, $expiration = 0 ) { - if (!$this->logging) return parent::setMulti($items,$expiration); - $start = microtime(true); - $name = 'setMulti'; - $arguments = array($items,$expiration); - $result = parent::setMulti($items,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setMultiByKey( $server_key, array $items, $expiration = 0 ) { - if (!$this->logging) return parent::setMultiByKey($server_key,$items,$expiration); - $start = microtime(true); - $name = 'setMultiByKey'; - $arguments = array($server_key,$items,$expiration); - $result = parent::setMultiByKey($server_key,$items,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function cas( $token, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::cas($token,$key,$value,$expiration); - $start = microtime(true); - $name = 'cas'; - $arguments = array($token,$key,$value,$expiration); - $result = parent::cas($token,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function casByKey( $token, $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::casByKey($token,$server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'casByKey'; - $arguments = array($token,$server_key,$key,$value,$expiration); - $result = parent::casByKey($token,$server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function add( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::add($key,$value,$expiration); - $start = microtime(true); - $name = 'add'; - $arguments = array($key,$value,$expiration); - $result = parent::add($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function addByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::addByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'addByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::addByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function append( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::append($key,$value,$expiration); - $start = microtime(true); - $name = 'append'; - $arguments = array($key,$value,$expiration); - $result = parent::append($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function appendByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::appendByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'appendByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::appendByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function prepend( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::prepend($key,$value,$expiration); - $start = microtime(true); - $name = 'prepend'; - $arguments = array($key,$value,$expiration); - $result = parent::prepend($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function prependByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::prependByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'prependByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::prependByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function replace( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::replace($key,$value,$expiration); - $start = microtime(true); - $name = 'replace'; - $arguments = array($key,$value,$expiration); - $result = parent::replace($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function replaceByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::replaceByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'replaceByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::replaceByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function delete( $key, $time = 0 ) { - if (!$this->logging) return parent::delete($key,$time); - $start = microtime(true); - $name = 'delete'; - $arguments = array($key,$time); - $result = parent::delete($key,$time); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function deleteByKey( $server_key, $key, $time = 0 ) { - if (!$this->logging) return parent::deleteByKey($server_key,$key,$time); - $start = microtime(true); - $name = 'deleteByKey'; - $arguments = array($server_key,$key,$time); - $result = parent::deleteByKey($server_key,$key,$time); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function deleteMulti( $keys, $expiration = 0 ) { - if (!$this->logging) return parent::deleteMulti($keys,$expiration); - $start = microtime(true); - $name = 'deleteMulti'; - $arguments = array($keys,$expiration); - $result = parent::deleteMulti($keys,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function deleteMultiByKey( $server_key, $keys, $expiration = 0 ) { - if (!$this->logging) return parent::deleteMultiByKey($server_key,$keys,$expiration); - $start = microtime(true); - $name = 'deleteMultiByKey'; - $arguments = array($server_key,$keys,$expiration); - $result = parent::deleteMultiByKey($server_key,$keys,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function increment( $key, $offset = 1, $initial_value = 0, $expiry = 0 ) { - if (!$this->logging) return parent::increment($key,$offset,$initial_value,$expiry); - $start = microtime(true); - $name = 'increment'; - $arguments = array($key,$offset,$initial_value,$expiry); - $result = parent::increment($key,$offset,$initial_value,$expiry); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function incrementByKey( $server_key, $key, $offset = 1, $initial_value = 0, $expiry = 0 ) { - if (!$this->logging) return parent::incrementByKey($server_key,$key,$offset,$initial_value,$expiry); - $start = microtime(true); - $name = 'incrementByKey'; - $arguments = array($server_key,$key,$offset,$initial_value,$expiry); - $result = parent::incrementByKey($server_key,$key,$offset,$initial_value,$expiry); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function decrement( $key, $offset = 1, $initial_value = 0, $expiry = 0 ) { - if (!$this->logging) return parent::decrement($key,$offset,$initial_value,$expiry); - $start = microtime(true); - $name = 'decrement'; - $arguments = array($key,$offset,$initial_value,$expiry); - $result = parent::decrement($key,$offset,$initial_value,$expiry); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function decrementByKey( $server_key, $key, $offset = 1, $initial_value = 0, $expiry = 0 ) { - if (!$this->logging) return parent::decrementByKey($server_key,$key,$offset,$initial_value,$expiry); - $start = microtime(true); - $name = 'decrementByKey'; - $arguments = array($server_key,$key,$offset,$initial_value,$expiry); - $result = parent::decrementByKey($server_key,$key,$offset,$initial_value,$expiry); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getOption( $option ) { - if (!$this->logging) return parent::getOption($option); - $start = microtime(true); - $name = 'getOption'; - $arguments = array($option); - $result = parent::getOption($option); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setOption( $option, $value ) { - if (!$this->logging) return parent::setOption($option,$value); - $start = microtime(true); - $name = 'setOption'; - $arguments = array($option,$value); - $result = parent::setOption($option,$value); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setOptions( $options ) { - if (!$this->logging) return parent::setOptions($options); - $start = microtime(true); - $name = 'setOptions'; - $arguments = array($options); - $result = parent::setOptions($options); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function addServer( $host, $port, $weight = 0 ) { - if (!$this->logging) return parent::addServer($host,$port,$weight); - $start = microtime(true); - $name = 'addServer'; - $arguments = array($host,$port,$weight); - $result = parent::addServer($host,$port,$weight); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function addServers( array $servers ) { - if (!$this->logging) return parent::addServers($servers); - $start = microtime(true); - $name = 'addServers'; - $arguments = array($servers); - $result = parent::addServers($servers); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getServerList( ) { - if (!$this->logging) return parent::getServerList(); - $start = microtime(true); - $name = 'getServerList'; - $arguments = array(); - $result = parent::getServerList(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getServerByKey( $server_key ) { - if (!$this->logging) return parent::getServerByKey($server_key); - $start = microtime(true); - $name = 'getServerByKey'; - $arguments = array($server_key); - $result = parent::getServerByKey($server_key); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function flush( $delay = 0 ) { - if (!$this->logging) return parent::flush($delay); - $start = microtime(true); - $name = 'flush'; - $arguments = array($delay); - $result = parent::flush($delay); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getStats( ) { - if (!$this->logging) return parent::getStats(); - $start = microtime(true); - $name = 'getStats'; - $arguments = array(); - $result = parent::getStats(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getVersion( ) { - if (!$this->logging) return parent::getVersion(); - $start = microtime(true); - $name = 'getVersion'; - $arguments = array(); - $result = parent::getVersion(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getResultCode( ) { - if (!$this->logging) return parent::getResultCode(); - $start = microtime(true); - $name = 'getResultCode'; - $arguments = array(); - $result = parent::getResultCode(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getResultMessage( ) { - if (!$this->logging) return parent::getResultMessage(); - $start = microtime(true); - $name = 'getResultMessage'; - $arguments = array(); - $result = parent::getResultMessage(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function isPersistent( ) { - if (!$this->logging) return parent::isPersistent(); - $start = microtime(true); - $name = 'isPersistent'; - $arguments = array(); - $result = parent::isPersistent(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function isPristine( ) { - if (!$this->logging) return parent::isPristine(); - $start = microtime(true); - $name = 'isPristine'; - $arguments = array(); - $result = parent::isPristine(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - } -} else if ($extension->getVersion()=='2.2.0') { - class LoggingMemcache extends \Memcached implements MemcacheInterface, LoggingMemcacheInterface { - public function __construct($logging, $persistent_id = '') { - $this->calls = array(); - $this->logging = $logging; - if ($persistent_id) { - $this->initialize = count($this->getServerList())==0; - } else { - $this->initialize = true; - } - parent::__construct($persistent_id); - } - private $calls; - private $initialize; - private $logging; - public function getLoggedCalls() { - return $this->calls; - } - private function logCall($start, $result) { - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function get( $key, $cache_cb = null, &$cas_token = null, &$udf_flags = null ) { - if (!$this->logging) return parent::get($key,$cache_cb,$cas_token,$udf_flags); - $start = microtime(true); - $name = 'get'; - $arguments = array($key,$cache_cb,$cas_token,$udf_flags); - $result = parent::get($key,$cache_cb,$cas_token,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getByKey( $server_key, $key, $cache_cb = null, &$cas_token = null, &$udf_flags = null ) { - if (!$this->logging) return parent::getByKey($server_key,$key,$cache_cb,$cas_token,$udf_flags); - $start = microtime(true); - $name = 'getByKey'; - $arguments = array($server_key,$key,$cache_cb,$cas_token,$udf_flags); - $result = parent::getByKey($server_key,$key,$cache_cb,$cas_token,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getMulti( array $keys, &$cas_tokens = null, $flags = null, &$udf_flags = null ) { - if (!$this->logging) return parent::getMulti($keys,$cas_tokens,$flags,$udf_flags); - $start = microtime(true); - $name = 'getMulti'; - $arguments = array($keys,$cas_tokens,$flags,$udf_flags); - $result = parent::getMulti($keys,$cas_tokens,$flags,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getMultiByKey( $server_key, array $keys, &$cas_tokens = null, $flags = null, &$udf_flags = null ) { - if (!$this->logging) return parent::getMultiByKey($server_key,$keys,$cas_tokens,$flags,$udf_flags); - $start = microtime(true); - $name = 'getMultiByKey'; - $arguments = array($server_key,$keys,$cas_tokens,$flags,$udf_flags); - $result = parent::getMultiByKey($server_key,$keys,$cas_tokens,$flags,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getDelayed( array $keys, $with_cas = null, $value_cb = null ) { - if (!$this->logging) return parent::getDelayed($keys,$with_cas,$value_cb); - $start = microtime(true); - $name = 'getDelayed'; - $arguments = array($keys,$with_cas,$value_cb); - $result = parent::getDelayed($keys,$with_cas,$value_cb); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getDelayedByKey( $server_key, array $keys, $with_cas = null, $value_cb = null ) { - if (!$this->logging) return parent::getDelayedByKey($server_key,$keys,$with_cas,$value_cb); - $start = microtime(true); - $name = 'getDelayedByKey'; - $arguments = array($server_key,$keys,$with_cas,$value_cb); - $result = parent::getDelayedByKey($server_key,$keys,$with_cas,$value_cb); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function fetch( ) { - if (!$this->logging) return parent::fetch(); - $start = microtime(true); - $name = 'fetch'; - $arguments = array(); - $result = parent::fetch(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function fetchAll( ) { - if (!$this->logging) return parent::fetchAll(); - $start = microtime(true); - $name = 'fetchAll'; - $arguments = array(); - $result = parent::fetchAll(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function set( $key, $value, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::set($key,$value,$expiration,$udf_flags); - $start = microtime(true); - $name = 'set'; - $arguments = array($key,$value,$expiration,$udf_flags); - $result = parent::set($key,$value,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function touch( $key, $expiration = 0 ) { - if (!$this->logging) return parent::touch($key,$expiration); - $start = microtime(true); - $name = 'touch'; - $arguments = array($key,$expiration); - $result = parent::touch($key,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function touchbyKey( $server_key, $key, $expiration = 0 ) { - if (!$this->logging) return parent::touchbyKey($server_key,$key,$expiration); - $start = microtime(true); - $name = 'touchbyKey'; - $arguments = array($server_key,$key,$expiration); - $result = parent::touchbyKey($server_key,$key,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setByKey( $server_key, $key, $value, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::setByKey($server_key,$key,$value,$expiration,$udf_flags); - $start = microtime(true); - $name = 'setByKey'; - $arguments = array($server_key,$key,$value,$expiration,$udf_flags); - $result = parent::setByKey($server_key,$key,$value,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setMulti( array $items, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::setMulti($items,$expiration,$udf_flags); - $start = microtime(true); - $name = 'setMulti'; - $arguments = array($items,$expiration,$udf_flags); - $result = parent::setMulti($items,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setMultiByKey( $server_key, array $items, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::setMultiByKey($server_key,$items,$expiration,$udf_flags); - $start = microtime(true); - $name = 'setMultiByKey'; - $arguments = array($server_key,$items,$expiration,$udf_flags); - $result = parent::setMultiByKey($server_key,$items,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function cas( $token, $key, $value, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::cas($token,$key,$value,$expiration,$udf_flags); - $start = microtime(true); - $name = 'cas'; - $arguments = array($token,$key,$value,$expiration,$udf_flags); - $result = parent::cas($token,$key,$value,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function casByKey( $token, $server_key, $key, $value, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::casByKey($token,$server_key,$key,$value,$expiration,$udf_flags); - $start = microtime(true); - $name = 'casByKey'; - $arguments = array($token,$server_key,$key,$value,$expiration,$udf_flags); - $result = parent::casByKey($token,$server_key,$key,$value,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function add( $key, $value, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::add($key,$value,$expiration,$udf_flags); - $start = microtime(true); - $name = 'add'; - $arguments = array($key,$value,$expiration,$udf_flags); - $result = parent::add($key,$value,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function addByKey( $server_key, $key, $value, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::addByKey($server_key,$key,$value,$expiration,$udf_flags); - $start = microtime(true); - $name = 'addByKey'; - $arguments = array($server_key,$key,$value,$expiration,$udf_flags); - $result = parent::addByKey($server_key,$key,$value,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function append( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::append($key,$value,$expiration); - $start = microtime(true); - $name = 'append'; - $arguments = array($key,$value,$expiration); - $result = parent::append($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function appendByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::appendByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'appendByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::appendByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function prepend( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::prepend($key,$value,$expiration); - $start = microtime(true); - $name = 'prepend'; - $arguments = array($key,$value,$expiration); - $result = parent::prepend($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function prependByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::prependByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'prependByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::prependByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function replace( $key, $value, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::replace($key,$value,$expiration,$udf_flags); - $start = microtime(true); - $name = 'replace'; - $arguments = array($key,$value,$expiration,$udf_flags); - $result = parent::replace($key,$value,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function replaceByKey( $server_key, $key, $value, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::replaceByKey($server_key,$key,$value,$expiration,$udf_flags); - $start = microtime(true); - $name = 'replaceByKey'; - $arguments = array($server_key,$key,$value,$expiration,$udf_flags); - $result = parent::replaceByKey($server_key,$key,$value,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function delete( $key, $time = 0 ) { - if (!$this->logging) return parent::delete($key,$time); - $start = microtime(true); - $name = 'delete'; - $arguments = array($key,$time); - $result = parent::delete($key,$time); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function deleteByKey( $server_key, $key, $time = 0 ) { - if (!$this->logging) return parent::deleteByKey($server_key,$key,$time); - $start = microtime(true); - $name = 'deleteByKey'; - $arguments = array($server_key,$key,$time); - $result = parent::deleteByKey($server_key,$key,$time); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function deleteMulti( $keys, $expiration = 0 ) { - if (!$this->logging) return parent::deleteMulti($keys,$expiration); - $start = microtime(true); - $name = 'deleteMulti'; - $arguments = array($keys,$expiration); - $result = parent::deleteMulti($keys,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function deleteMultiByKey( $server_key, $keys, $expiration = 0 ) { - if (!$this->logging) return parent::deleteMultiByKey($server_key,$keys,$expiration); - $start = microtime(true); - $name = 'deleteMultiByKey'; - $arguments = array($server_key,$keys,$expiration); - $result = parent::deleteMultiByKey($server_key,$keys,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function increment( $key, $offset = 1, $initial_value = 0, $expiry = 0) { - if (!$this->logging) return parent::increment($key,$offset,$initial_value,$expiry); - $start = microtime(true); - $name = 'increment'; - $arguments = array($key,$offset,$initial_value,$expiry); - $result = parent::increment($key,$offset,$initial_value,$expiry); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function incrementByKey( $server_key, $key, $offset = 1, $initial_value = 0, $expiry = 0 ) { - if (!$this->logging) return parent::incrementByKey($server_key,$key,$offset,$initial_value,$expiry); - $start = microtime(true); - $name = 'incrementByKey'; - $arguments = array($server_key,$key,$offset,$initial_value,$expiry); - $result = parent::incrementByKey($server_key,$key,$offset,$initial_value,$expiry); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function decrement( $key, $offset = 1, $initial_value = 0, $expiry = 0) { - if (!$this->logging) return parent::decrement($key,$offset,$initial_value,$expiry); - $start = microtime(true); - $name = 'decrement'; - $arguments = array($key,$offset,$initial_value,$expiry); - $result = parent::decrement($key,$offset,$initial_value,$expiry); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function decrementByKey( $server_key, $key, $offset = 1, $initial_value = 0, $expiry = 0 ) { - if (!$this->logging) return parent::decrementByKey($server_key,$key,$offset,$initial_value,$expiry); - $start = microtime(true); - $name = 'decrementByKey'; - $arguments = array($server_key,$key,$offset,$initial_value,$expiry); - $result = parent::decrementByKey($server_key,$key,$offset,$initial_value,$expiry); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getOption( $option ) { - if (!$this->logging) return parent::getOption($option); - $start = microtime(true); - $name = 'getOption'; - $arguments = array($option); - $result = parent::getOption($option); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setOption( $option, $value ) { - if (!$this->logging) return parent::setOption($option,$value); - $start = microtime(true); - $name = 'setOption'; - $arguments = array($option,$value); - $result = parent::setOption($option,$value); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setOptions( $options ) { - if (!$this->logging) return parent::setOptions($options); - $start = microtime(true); - $name = 'setOptions'; - $arguments = array($options); - $result = parent::setOptions($options); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setBucket( $host_map, $forward_map, $replicas ) { - if (!$this->logging) return parent::setBucket($host_map,$forward_map,$replicas); - $start = microtime(true); - $name = 'setBucket'; - $arguments = array($host_map,$forward_map,$replicas); - $result = parent::setBucket($host_map,$forward_map,$replicas); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function addServer( $host, $port, $weight = 0 ) { - if (!$this->logging) return parent::addServer($host,$port,$weight); - $start = microtime(true); - $name = 'addServer'; - $arguments = array($host,$port,$weight); - $result = parent::addServer($host,$port,$weight); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function addServers( array $servers ) { - if (!$this->logging) return parent::addServers($servers); - $start = microtime(true); - $name = 'addServers'; - $arguments = array($servers); - $result = parent::addServers($servers); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getServerList( ) { - if (!$this->logging) return parent::getServerList(); - $start = microtime(true); - $name = 'getServerList'; - $arguments = array(); - $result = parent::getServerList(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getServerByKey( $server_key ) { - if (!$this->logging) return parent::getServerByKey($server_key); - $start = microtime(true); - $name = 'getServerByKey'; - $arguments = array($server_key); - $result = parent::getServerByKey($server_key); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getLastErrorMessage( ) { - if (!$this->logging) return parent::getLastErrorMessage(); - $start = microtime(true); - $name = 'getLastErrorMessage'; - $arguments = array(); - $result = parent::getLastErrorMessage(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getLastErrorCode( ) { - if (!$this->logging) return parent::getLastErrorCode(); - $start = microtime(true); - $name = 'getLastErrorCode'; - $arguments = array(); - $result = parent::getLastErrorCode(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getLastErrorErrno( ) { - if (!$this->logging) return parent::getLastErrorErrno(); - $start = microtime(true); - $name = 'getLastErrorErrno'; - $arguments = array(); - $result = parent::getLastErrorErrno(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getLastDisconnectedServer( ) { - if (!$this->logging) return parent::getLastDisconnectedServer(); - $start = microtime(true); - $name = 'getLastDisconnectedServer'; - $arguments = array(); - $result = parent::getLastDisconnectedServer(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function flush( $delay = 0 ) { - if (!$this->logging) return parent::flush($delay); - $start = microtime(true); - $name = 'flush'; - $arguments = array($delay); - $result = parent::flush($delay); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getStats( ) { - if (!$this->logging) return parent::getStats(); - $start = microtime(true); - $name = 'getStats'; - $arguments = array(); - $result = parent::getStats(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getVersion( ) { - if (!$this->logging) return parent::getVersion(); - $start = microtime(true); - $name = 'getVersion'; - $arguments = array(); - $result = parent::getVersion(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getResultCode( ) { - if (!$this->logging) return parent::getResultCode(); - $start = microtime(true); - $name = 'getResultCode'; - $arguments = array(); - $result = parent::getResultCode(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getResultMessage( ) { - if (!$this->logging) return parent::getResultMessage(); - $start = microtime(true); - $name = 'getResultMessage'; - $arguments = array(); - $result = parent::getResultMessage(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function isPersistent( ) { - if (!$this->logging) return parent::isPersistent(); - $start = microtime(true); - $name = 'isPersistent'; - $arguments = array(); - $result = parent::isPersistent(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function isPristine( ) { - if (!$this->logging) return parent::isPristine(); - $start = microtime(true); - $name = 'isPristine'; - $arguments = array(); - $result = parent::isPristine(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setSaslAuthData( $username, $password ) { - if (!$this->logging) return parent::setSaslAuthData($username,$password); - $start = microtime(true); - $name = 'setSaslAuthData'; - $arguments = array($username,$password); - $result = parent::setSaslAuthData($username,$password); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - } -} else if ($extension->getVersion()=='2.2.0b1') { - class LoggingMemcache extends \Memcached implements MemcacheInterface, LoggingMemcacheInterface { - public function __construct($logging, $persistent_id = '') { - $this->calls = array(); - $this->logging = $logging; - if ($persistent_id) { - $this->initialize = count($this->getServerList())==0; - } else { - $this->initialize = true; + public function findServer($key) { + if ($this->logging) { + $start = microtime(true); + $name = 'findServer'; + $arguments = array($key); + } + list($_key) = array($key); + $result = parent::findServer($_key); + list($key) = array($_key); + if ($this->logging) { + $time = microtime(true) - $start; + $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); } - parent::__construct($persistent_id); - } - private $calls; - private $initialize; - private $logging; - public function getLoggedCalls() { - return $this->calls; - } - private function logCall($start, $result) { - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function get( $key, $cache_cb = null, &$cas_token = null, &$udf_flags = null ) { - if (!$this->logging) return parent::get($key,$cache_cb,$cas_token,$udf_flags); - $start = microtime(true); - $name = 'get'; - $arguments = array($key,$cache_cb,$cas_token,$udf_flags); - $result = parent::get($key,$cache_cb,$cas_token,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getByKey( $server_key, $key, $cache_cb = null, &$cas_token = null, &$udf_flags = null ) { - if (!$this->logging) return parent::getByKey($server_key,$key,$cache_cb,$cas_token,$udf_flags); - $start = microtime(true); - $name = 'getByKey'; - $arguments = array($server_key,$key,$cache_cb,$cas_token,$udf_flags); - $result = parent::getByKey($server_key,$key,$cache_cb,$cas_token,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getMulti( array $keys, &$cas_tokens = null, $flags = null, &$udf_flags = null ) { - if (!$this->logging) return parent::getMulti($keys,$cas_tokens,$flags,$udf_flags); - $start = microtime(true); - $name = 'getMulti'; - $arguments = array($keys,$cas_tokens,$flags,$udf_flags); - $result = parent::getMulti($keys,$cas_tokens,$flags,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getMultiByKey( $server_key, array $keys, &$cas_tokens = null, $flags = null, &$udf_flags = null ) { - if (!$this->logging) return parent::getMultiByKey($server_key,$keys,$cas_tokens,$flags,$udf_flags); - $start = microtime(true); - $name = 'getMultiByKey'; - $arguments = array($server_key,$keys,$cas_tokens,$flags,$udf_flags); - $result = parent::getMultiByKey($server_key,$keys,$cas_tokens,$flags,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getDelayed( array $keys, $with_cas = null, $value_cb = null ) { - if (!$this->logging) return parent::getDelayed($keys,$with_cas,$value_cb); - $start = microtime(true); - $name = 'getDelayed'; - $arguments = array($keys,$with_cas,$value_cb); - $result = parent::getDelayed($keys,$with_cas,$value_cb); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getDelayedByKey( $server_key, array $keys, $with_cas = null, $value_cb = null ) { - if (!$this->logging) return parent::getDelayedByKey($server_key,$keys,$with_cas,$value_cb); - $start = microtime(true); - $name = 'getDelayedByKey'; - $arguments = array($server_key,$keys,$with_cas,$value_cb); - $result = parent::getDelayedByKey($server_key,$keys,$with_cas,$value_cb); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function fetch( ) { - if (!$this->logging) return parent::fetch(); - $start = microtime(true); - $name = 'fetch'; - $arguments = array(); - $result = parent::fetch(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function fetchAll( ) { - if (!$this->logging) return parent::fetchAll(); - $start = microtime(true); - $name = 'fetchAll'; - $arguments = array(); - $result = parent::fetchAll(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function set( $key, $value, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::set($key,$value,$expiration,$udf_flags); - $start = microtime(true); - $name = 'set'; - $arguments = array($key,$value,$expiration,$udf_flags); - $result = parent::set($key,$value,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function touch( $key, $expiration = 0 ) { - if (!$this->logging) return parent::touch($key,$expiration); - $start = microtime(true); - $name = 'touch'; - $arguments = array($key,$expiration); - $result = parent::touch($key,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function touchbyKey( $server_key, $key, $expiration = 0 ) { - if (!$this->logging) return parent::touchbyKey($server_key,$key,$expiration); - $start = microtime(true); - $name = 'touchbyKey'; - $arguments = array($server_key,$key,$expiration); - $result = parent::touchbyKey($server_key,$key,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setByKey( $server_key, $key, $value, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::setByKey($server_key,$key,$value,$expiration,$udf_flags); - $start = microtime(true); - $name = 'setByKey'; - $arguments = array($server_key,$key,$value,$expiration,$udf_flags); - $result = parent::setByKey($server_key,$key,$value,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setMulti( array $items, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::setMulti($items,$expiration,$udf_flags); - $start = microtime(true); - $name = 'setMulti'; - $arguments = array($items,$expiration,$udf_flags); - $result = parent::setMulti($items,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setMultiByKey( $server_key, array $items, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::setMultiByKey($server_key,$items,$expiration,$udf_flags); - $start = microtime(true); - $name = 'setMultiByKey'; - $arguments = array($server_key,$items,$expiration,$udf_flags); - $result = parent::setMultiByKey($server_key,$items,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function cas( $token, $key, $value, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::cas($token,$key,$value,$expiration,$udf_flags); - $start = microtime(true); - $name = 'cas'; - $arguments = array($token,$key,$value,$expiration,$udf_flags); - $result = parent::cas($token,$key,$value,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function casByKey( $token, $server_key, $key, $value, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::casByKey($token,$server_key,$key,$value,$expiration,$udf_flags); - $start = microtime(true); - $name = 'casByKey'; - $arguments = array($token,$server_key,$key,$value,$expiration,$udf_flags); - $result = parent::casByKey($token,$server_key,$key,$value,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function add( $key, $value, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::add($key,$value,$expiration,$udf_flags); - $start = microtime(true); - $name = 'add'; - $arguments = array($key,$value,$expiration,$udf_flags); - $result = parent::add($key,$value,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function addByKey( $server_key, $key, $value, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::addByKey($server_key,$key,$value,$expiration,$udf_flags); - $start = microtime(true); - $name = 'addByKey'; - $arguments = array($server_key,$key,$value,$expiration,$udf_flags); - $result = parent::addByKey($server_key,$key,$value,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function append( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::append($key,$value,$expiration); - $start = microtime(true); - $name = 'append'; - $arguments = array($key,$value,$expiration); - $result = parent::append($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function appendByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::appendByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'appendByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::appendByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function prepend( $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::prepend($key,$value,$expiration); - $start = microtime(true); - $name = 'prepend'; - $arguments = array($key,$value,$expiration); - $result = parent::prepend($key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function prependByKey( $server_key, $key, $value, $expiration = 0 ) { - if (!$this->logging) return parent::prependByKey($server_key,$key,$value,$expiration); - $start = microtime(true); - $name = 'prependByKey'; - $arguments = array($server_key,$key,$value,$expiration); - $result = parent::prependByKey($server_key,$key,$value,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function replace( $key, $value, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::replace($key,$value,$expiration,$udf_flags); - $start = microtime(true); - $name = 'replace'; - $arguments = array($key,$value,$expiration,$udf_flags); - $result = parent::replace($key,$value,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function replaceByKey( $server_key, $key, $value, $expiration = 0, $udf_flags = 0 ) { - if (!$this->logging) return parent::replaceByKey($server_key,$key,$value,$expiration,$udf_flags); - $start = microtime(true); - $name = 'replaceByKey'; - $arguments = array($server_key,$key,$value,$expiration,$udf_flags); - $result = parent::replaceByKey($server_key,$key,$value,$expiration,$udf_flags); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function delete( $key, $time = 0 ) { - if (!$this->logging) return parent::delete($key,$time); - $start = microtime(true); - $name = 'delete'; - $arguments = array($key,$time); - $result = parent::delete($key,$time); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function deleteByKey( $server_key, $key, $time = 0 ) { - if (!$this->logging) return parent::deleteByKey($server_key,$key,$time); - $start = microtime(true); - $name = 'deleteByKey'; - $arguments = array($server_key,$key,$time); - $result = parent::deleteByKey($server_key,$key,$time); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function deleteMulti( $keys, $expiration = 0 ) { - if (!$this->logging) return parent::deleteMulti($keys,$expiration); - $start = microtime(true); - $name = 'deleteMulti'; - $arguments = array($keys,$expiration); - $result = parent::deleteMulti($keys,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function deleteMultiByKey( $server_key, $keys, $expiration = 0 ) { - if (!$this->logging) return parent::deleteMultiByKey($server_key,$keys,$expiration); - $start = microtime(true); - $name = 'deleteMultiByKey'; - $arguments = array($server_key,$keys,$expiration); - $result = parent::deleteMultiByKey($server_key,$keys,$expiration); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function increment( $key, $offset = 1, $initial_value = 0, $expiry = 0) { - if (!$this->logging) return parent::increment($key,$offset,$initial_value,$expiry); - $start = microtime(true); - $name = 'increment'; - $arguments = array($key,$offset,$initial_value,$expiry); - $result = parent::increment($key,$offset,$initial_value,$expiry); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function incrementByKey( $server_key, $key, $offset = 1, $initial_value = 0, $expiry = 0 ) { - if (!$this->logging) return parent::incrementByKey($server_key,$key,$offset,$initial_value,$expiry); - $start = microtime(true); - $name = 'incrementByKey'; - $arguments = array($server_key,$key,$offset,$initial_value,$expiry); - $result = parent::incrementByKey($server_key,$key,$offset,$initial_value,$expiry); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function decrement( $key, $offset = 1, $initial_value = 0, $expiry = 0) { - if (!$this->logging) return parent::decrement($key,$offset,$initial_value,$expiry); - $start = microtime(true); - $name = 'decrement'; - $arguments = array($key,$offset,$initial_value,$expiry); - $result = parent::decrement($key,$offset,$initial_value,$expiry); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function decrementByKey( $server_key, $key, $offset = 1, $initial_value = 0, $expiry = 0 ) { - if (!$this->logging) return parent::decrementByKey($server_key,$key,$offset,$initial_value,$expiry); - $start = microtime(true); - $name = 'decrementByKey'; - $arguments = array($server_key,$key,$offset,$initial_value,$expiry); - $result = parent::decrementByKey($server_key,$key,$offset,$initial_value,$expiry); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getOption( $option ) { - if (!$this->logging) return parent::getOption($option); - $start = microtime(true); - $name = 'getOption'; - $arguments = array($option); - $result = parent::getOption($option); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setOption( $option, $value ) { - if (!$this->logging) return parent::setOption($option,$value); - $start = microtime(true); - $name = 'setOption'; - $arguments = array($option,$value); - $result = parent::setOption($option,$value); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setOptions( $options ) { - if (!$this->logging) return parent::setOptions($options); - $start = microtime(true); - $name = 'setOptions'; - $arguments = array($options); - $result = parent::setOptions($options); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setBucket( $host_map, $forward_map, $replicas ) { - if (!$this->logging) return parent::setBucket($host_map,$forward_map,$replicas); - $start = microtime(true); - $name = 'setBucket'; - $arguments = array($host_map,$forward_map,$replicas); - $result = parent::setBucket($host_map,$forward_map,$replicas); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function addServer( $host, $port, $weight = 0 ) { - if (!$this->logging) return parent::addServer($host,$port,$weight); - $start = microtime(true); - $name = 'addServer'; - $arguments = array($host,$port,$weight); - $result = parent::addServer($host,$port,$weight); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function addServers( array $servers ) { - if (!$this->logging) return parent::addServers($servers); - $start = microtime(true); - $name = 'addServers'; - $arguments = array($servers); - $result = parent::addServers($servers); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getServerList( ) { - if (!$this->logging) return parent::getServerList(); - $start = microtime(true); - $name = 'getServerList'; - $arguments = array(); - $result = parent::getServerList(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getServerByKey( $server_key ) { - if (!$this->logging) return parent::getServerByKey($server_key); - $start = microtime(true); - $name = 'getServerByKey'; - $arguments = array($server_key); - $result = parent::getServerByKey($server_key); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getLastErrorMessage( ) { - if (!$this->logging) return parent::getLastErrorMessage(); - $start = microtime(true); - $name = 'getLastErrorMessage'; - $arguments = array(); - $result = parent::getLastErrorMessage(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getLastErrorCode( ) { - if (!$this->logging) return parent::getLastErrorCode(); - $start = microtime(true); - $name = 'getLastErrorCode'; - $arguments = array(); - $result = parent::getLastErrorCode(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getLastErrorErrno( ) { - if (!$this->logging) return parent::getLastErrorErrno(); - $start = microtime(true); - $name = 'getLastErrorErrno'; - $arguments = array(); - $result = parent::getLastErrorErrno(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getLastDisconnectedServer( ) { - if (!$this->logging) return parent::getLastDisconnectedServer(); - $start = microtime(true); - $name = 'getLastDisconnectedServer'; - $arguments = array(); - $result = parent::getLastDisconnectedServer(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function flush( $delay = 0 ) { - if (!$this->logging) return parent::flush($delay); - $start = microtime(true); - $name = 'flush'; - $arguments = array($delay); - $result = parent::flush($delay); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getStats( ) { - if (!$this->logging) return parent::getStats(); - $start = microtime(true); - $name = 'getStats'; - $arguments = array(); - $result = parent::getStats(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getVersion( ) { - if (!$this->logging) return parent::getVersion(); - $start = microtime(true); - $name = 'getVersion'; - $arguments = array(); - $result = parent::getVersion(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getResultCode( ) { - if (!$this->logging) return parent::getResultCode(); - $start = microtime(true); - $name = 'getResultCode'; - $arguments = array(); - $result = parent::getResultCode(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function getResultMessage( ) { - if (!$this->logging) return parent::getResultMessage(); - $start = microtime(true); - $name = 'getResultMessage'; - $arguments = array(); - $result = parent::getResultMessage(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function isPersistent( ) { - if (!$this->logging) return parent::isPersistent(); - $start = microtime(true); - $name = 'isPersistent'; - $arguments = array(); - $result = parent::isPersistent(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function isPristine( ) { - if (!$this->logging) return parent::isPristine(); - $start = microtime(true); - $name = 'isPristine'; - $arguments = array(); - $result = parent::isPristine(); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); - return $result; - } - public function setSaslAuthData( $username, $password ) { - if (!$this->logging) return parent::setSaslAuthData($username,$password); - $start = microtime(true); - $name = 'setSaslAuthData'; - $arguments = array($username,$password); - $result = parent::setSaslAuthData($username,$password); - $time = microtime(true) - $start; - $this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); return $result; } } } else { - throw new \Exception('LswMemcacheBundle does not support version '.$extension->getVersion().' of the memcached extension.'); + throw new \Exception('LswMemcacheBundle does not support version '.$extension->getVersion().' of the memcache extension.'); } diff --git a/Cache/LoggingMemcacheInterface.php b/Cache/LoggingMemcacheInterface.php index ec8f123..263bdd0 100644 --- a/Cache/LoggingMemcacheInterface.php +++ b/Cache/LoggingMemcacheInterface.php @@ -7,9 +7,9 @@ interface LoggingMemcacheInterface { /** - * Get the logged calls for this Memcached object + * Get the logged calls for this Memcache object * - * @return array Array of calls made to the Memcached object + * @return array Array of calls made to the Memcache object */ public function getLoggedCalls(); diff --git a/Cache/MemcacheInterface.php b/Cache/MemcacheInterface.php index 0abc46d..5df0814 100644 --- a/Cache/MemcacheInterface.php +++ b/Cache/MemcacheInterface.php @@ -1,254 +1,30 @@ getVersion()=='1.0.2') { +$extension = new \ReflectionExtension('memcache'); +if ($extension->getVersion()=='3.0.8') { interface MemcacheInterface { - public function get( $key, $cache_cb = null, &$cas_token = null ); - public function getByKey( $server_key, $key, $cache_cb = null, &$cas_token = null ); - public function getMulti( array $keys, &$cas_tokens = null, $flags = 0 ); - public function getMultiByKey( $server_key, array $keys, &$cas_tokens = null, $flags = 0 ); - public function getDelayed( array $keys, $with_cas = null, $value_cb = null ); - public function getDelayedByKey( $server_key, array $keys, $with_cas = null, $value_cb = null ); - public function fetch( ); - public function fetchAll( ); - public function set( $key, $value, $expiration = 0 ); - public function setByKey( $server_key, $key, $value, $expiration = 0 ); - public function setMulti( array $items, $expiration = 0 ); - public function setMultiByKey( $server_key, array $items, $expiration = 0 ); - public function cas( $token, $key, $value, $expiration = 0 ); - public function casByKey( $token, $server_key, $key, $value, $expiration = 0 ); - public function add( $key, $value, $expiration = 0 ); - public function addByKey( $server_key, $key, $value, $expiration = 0 ); - public function append( $key, $value, $expiration = 0 ); - public function appendByKey( $server_key, $key, $value, $expiration = 0 ); - public function prepend( $key, $value, $expiration = 0 ); - public function prependByKey( $server_key, $key, $value, $expiration = 0 ); - public function replace( $key, $value, $expiration = 0 ); - public function replaceByKey( $serve_key, $key, $value, $expiration = 0 ); - public function delete( $key, $time = 0 ); - public function deleteByKey( $server_key, $key, $time = 0 ); - public function increment( $key, $offset = 1); - public function decrement( $key, $offset = 1); - public function getOption( $option ); - public function setOption( $option, $value ); - public function addServer( $host, $port, $weight = 0 ); - public function addServers( array $servers ); - public function getServerList( ); - public function getServerByKey( $server_key ); - public function flush( $delay = 0 ); - public function getStats( ); - public function getResultCode( ); - public function getResultMessage( ); - } -} else if ($extension->getVersion()=='2.0.1') { - interface MemcacheInterface { - public function get( $key, $cache_cb = null, &$cas_token = null ); - public function getByKey( $server_key, $key, $cache_cb = null, &$cas_token = null ); - public function getMulti( array $keys, &$cas_tokens = null, $flags = null ); - public function getMultiByKey( $server_key, array $keys, &$cas_tokens = null, $flags = null ); - public function getDelayed( array $keys, $with_cas = null, $value_cb = null ); - public function getDelayedByKey( $server_key, array $keys, $with_cas = null, $value_cb = null ); - public function fetch( ); - public function fetchAll( ); - public function set( $key, $value, $expiration = 0 ); - public function touch( $key, $expiration = 0 ); - public function touchbyKey( $server_key, $key, $expiration = 0 ); - public function setByKey( $server_key, $key, $value, $expiration = 0 ); - public function setMulti( array $items, $expiration = 0 ); - public function setMultiByKey( $server_key, array $items, $expiration = 0 ); - public function cas( $token, $key, $value, $expiration = 0 ); - public function casByKey( $token, $server_key, $key, $value, $expiration = 0 ); - public function add( $key, $value, $expiration = 0 ); - public function addByKey( $server_key, $key, $value, $expiration = 0 ); - public function append( $key, $value, $expiration = 0 ); - public function appendByKey( $server_key, $key, $value, $expiration = 0 ); - public function prepend( $key, $value, $expiration = 0 ); - public function prependByKey( $server_key, $key, $value, $expiration = 0 ); - public function replace( $key, $value, $expiration = 0 ); - public function replaceByKey( $server_key, $key, $value, $expiration = 0 ); - public function delete( $key, $time = 0 ); - public function deleteByKey( $server_key, $key, $time = 0 ); - public function deleteMulti( $keys, $expiration = 0 ); - public function deleteMultiByKey( $server_key, $keys, $expiration = 0 ); - public function increment( $key, $offset = 1, $initial_value = 0, $expiry = 0 ); - public function incrementByKey( $server_key, $key, $offset = 1, $initial_value = 0, $expiry = 0 ); - public function decrement( $key, $offset = 1, $initial_value = 0, $expiry = 0 ); - public function decrementByKey( $server_key, $key, $offset = 1, $initial_value = 0, $expiry = 0 ); - public function getOption( $option ); - public function setOption( $option, $value ); - public function setOptions( $options ); - public function addServer( $host, $port, $weight = 0 ); - public function addServers( array $servers ); - public function getServerList( ); - public function getServerByKey( $server_key ); - public function flush( $delay = 0 ); - public function getStats( ); - public function getVersion( ); - public function getResultCode( ); - public function getResultMessage( ); - public function isPersistent( ); - public function isPristine( ); - } -} else if ($extension->getVersion()=='2.1.0') { - interface MemcacheInterface { - public function get( $key, $cache_cb = null, &$cas_token = null ); - public function getByKey( $server_key, $key, $cache_cb = null, &$cas_token = null ); - public function getMulti( array $keys, &$cas_tokens = null, $flags = null ); - public function getMultiByKey( $server_key, array $keys, &$cas_tokens = null, $flags = null ); - public function getDelayed( array $keys, $with_cas = null, $value_cb = null ); - public function getDelayedByKey( $server_key, array $keys, $with_cas = null, $value_cb = null ); - public function fetch( ); - public function fetchAll( ); - public function set( $key, $value, $expiration = 0 ); - public function touch( $key, $expiration = 0 ); - public function touchbyKey( $server_key, $key, $expiration = 0 ); - public function setByKey( $server_key, $key, $value, $expiration = 0 ); - public function setMulti( array $items, $expiration = 0 ); - public function setMultiByKey( $server_key, array $items, $expiration = 0 ); - public function cas( $token, $key, $value, $expiration = 0 ); - public function casByKey( $token, $server_key, $key, $value, $expiration = 0 ); - public function add( $key, $value, $expiration = 0 ); - public function addByKey( $server_key, $key, $value, $expiration = 0 ); - public function append( $key, $value, $expiration = 0 ); - public function appendByKey( $server_key, $key, $value, $expiration = 0 ); - public function prepend( $key, $value, $expiration = 0 ); - public function prependByKey( $server_key, $key, $value, $expiration = 0 ); - public function replace( $key, $value, $expiration = 0 ); - public function replaceByKey( $server_key, $key, $value, $expiration = 0 ); - public function delete( $key, $time = 0 ); - public function deleteByKey( $server_key, $key, $time = 0 ); - public function deleteMulti( $keys, $expiration = 0 ); - public function deleteMultiByKey( $server_key, $keys, $expiration = 0 ); - public function increment( $key, $offset = 1, $initial_value = 0, $expiry = 0 ); - public function incrementByKey( $server_key, $key, $offset = 1, $initial_value = 0, $expiry = 0 ); - public function decrement( $key, $offset = 1, $initial_value = 0, $expiry = 0 ); - public function decrementByKey( $server_key, $key, $offset = 1, $initial_value = 0, $expiry = 0 ); - public function getOption( $option ); - public function setOption( $option, $value ); - public function setOptions( $options ); - public function addServer( $host, $port, $weight = 0 ); - public function addServers( array $servers ); - public function getServerList( ); - public function getServerByKey( $server_key ); - public function flush( $delay = 0 ); - public function getStats( ); - public function getVersion( ); - public function getResultCode( ); - public function getResultMessage( ); - public function isPersistent( ); - public function isPristine( ); - } -} else if ($extension->getVersion()=='2.2.0') { - interface MemcacheInterface { - public function get( $key, $cache_cb = null, &$cas_token = null, &$udf_flags = null ); - public function getByKey( $server_key, $key, $cache_cb = null, &$cas_token = null, &$udf_flags = null ); - public function getMulti( array $keys, &$cas_tokens = null, $flags = null, &$udf_flags = null ); - public function getMultiByKey( $server_key, array $keys, &$cas_tokens = null, $flags = null, &$udf_flags = null ); - public function getDelayed( array $keys, $with_cas = null, $value_cb = null ); - public function getDelayedByKey( $server_key, array $keys, $with_cas = null, $value_cb = null ); - public function fetch( ); - public function fetchAll( ); - public function set( $key, $value, $expiration = 0, $udf_flags = 0 ); - public function touch( $key, $expiration = 0 ); - public function touchbyKey( $server_key, $key, $expiration = 0 ); - public function setByKey( $server_key, $key, $value, $expiration = 0, $udf_flags = 0 ); - public function setMulti( array $items, $expiration = 0, $udf_flags = 0 ); - public function setMultiByKey( $server_key, array $items, $expiration = 0, $udf_flags = 0 ); - public function cas( $token, $key, $value, $expiration = 0, $udf_flags = 0 ); - public function casByKey( $token, $server_key, $key, $value, $expiration = 0, $udf_flags = 0 ); - public function add( $key, $value, $expiration = 0, $udf_flags = 0 ); - public function addByKey( $server_key, $key, $value, $expiration = 0, $udf_flags = 0 ); - public function append( $key, $value, $expiration = 0 ); - public function appendByKey( $server_key, $key, $value, $expiration = 0 ); - public function prepend( $key, $value, $expiration = 0 ); - public function prependByKey( $server_key, $key, $value, $expiration = 0 ); - public function replace( $key, $value, $expiration = 0, $udf_flags = 0 ); - public function replaceByKey( $server_key, $key, $value, $expiration = 0, $udf_flags = 0 ); - public function delete( $key, $time = 0 ); - public function deleteByKey( $server_key, $key, $time = 0 ); - public function deleteMulti( $keys, $expiration = 0 ); - public function deleteMultiByKey( $server_key, $keys, $expiration = 0 ); - public function increment( $key, $offset = 1, $initial_value = 0, $expiry = 0); - public function incrementByKey( $server_key, $key, $offset = 1, $initial_value = 0, $expiry = 0 ); - public function decrement( $key, $offset = 1, $initial_value = 0, $expiry = 0); - public function decrementByKey( $server_key, $key, $offset = 1, $initial_value = 0, $expiry = 0 ); - public function getOption( $option ); - public function setOption( $option, $value ); - public function setOptions( $options ); - public function setBucket( $host_map, $forward_map, $replicas ); - public function addServer( $host, $port, $weight = 0 ); - public function addServers( array $servers ); - public function getServerList( ); - public function getServerByKey( $server_key ); - public function getLastErrorMessage( ); - public function getLastErrorCode( ); - public function getLastErrorErrno( ); - public function getLastDisconnectedServer( ); - public function flush( $delay = 0 ); - public function getStats( ); - public function getVersion( ); - public function getResultCode( ); - public function getResultMessage( ); - public function isPersistent( ); - public function isPristine( ); - public function setSaslAuthData( $username, $password ); - } -} else if ($extension->getVersion()=='2.2.0b1') { - interface MemcacheInterface { - public function get( $key, $cache_cb = null, &$cas_token = null, &$udf_flags = null ); - public function getByKey( $server_key, $key, $cache_cb = null, &$cas_token = null, &$udf_flags = null ); - public function getMulti( array $keys, &$cas_tokens = null, $flags = null, &$udf_flags = null ); - public function getMultiByKey( $server_key, array $keys, &$cas_tokens = null, $flags = null, &$udf_flags = null ); - public function getDelayed( array $keys, $with_cas = null, $value_cb = null ); - public function getDelayedByKey( $server_key, array $keys, $with_cas = null, $value_cb = null ); - public function fetch( ); - public function fetchAll( ); - public function set( $key, $value, $expiration = 0, $udf_flags = 0 ); - public function touch( $key, $expiration = 0 ); - public function touchbyKey( $server_key, $key, $expiration = 0 ); - public function setByKey( $server_key, $key, $value, $expiration = 0, $udf_flags = 0 ); - public function setMulti( array $items, $expiration = 0, $udf_flags = 0 ); - public function setMultiByKey( $server_key, array $items, $expiration = 0, $udf_flags = 0 ); - public function cas( $token, $key, $value, $expiration = 0, $udf_flags = 0 ); - public function casByKey( $token, $server_key, $key, $value, $expiration = 0, $udf_flags = 0 ); - public function add( $key, $value, $expiration = 0, $udf_flags = 0 ); - public function addByKey( $server_key, $key, $value, $expiration = 0, $udf_flags = 0 ); - public function append( $key, $value, $expiration = 0 ); - public function appendByKey( $server_key, $key, $value, $expiration = 0 ); - public function prepend( $key, $value, $expiration = 0 ); - public function prependByKey( $server_key, $key, $value, $expiration = 0 ); - public function replace( $key, $value, $expiration = 0, $udf_flags = 0 ); - public function replaceByKey( $server_key, $key, $value, $expiration = 0, $udf_flags = 0 ); - public function delete( $key, $time = 0 ); - public function deleteByKey( $server_key, $key, $time = 0 ); - public function deleteMulti( $keys, $expiration = 0 ); - public function deleteMultiByKey( $server_key, $keys, $expiration = 0 ); - public function increment( $key, $offset = 1, $initial_value = 0, $expiry = 0); - public function incrementByKey( $server_key, $key, $offset = 1, $initial_value = 0, $expiry = 0 ); - public function decrement( $key, $offset = 1, $initial_value = 0, $expiry = 0); - public function decrementByKey( $server_key, $key, $offset = 1, $initial_value = 0, $expiry = 0 ); - public function getOption( $option ); - public function setOption( $option, $value ); - public function setOptions( $options ); - public function setBucket( $host_map, $forward_map, $replicas ); - public function addServer( $host, $port, $weight = 0 ); - public function addServers( array $servers ); - public function getServerList( ); - public function getServerByKey( $server_key ); - public function getLastErrorMessage( ); - public function getLastErrorCode( ); - public function getLastErrorErrno( ); - public function getLastDisconnectedServer( ); - public function flush( $delay = 0 ); - public function getStats( ); - public function getVersion( ); - public function getResultCode( ); - public function getResultMessage( ); - public function isPersistent( ); - public function isPristine( ); - public function setSaslAuthData( $username, $password ); + public function setFailureCallback($failureCallback); + public function getServerStatus($host,$port=11211); + public function getVersion(); + public function add($key,$var=null,$flag=0,$exptime=0); + public function set($key,$var=null,$flag=0,$exptime=0); + public function replace($key,$var=null,$flag=0,$exptime=0); + public function cas($key,$var=null,$flag=0,$exptime=0,$cas=0); + public function prepend($key,$var=null,$flag=0,$exptime=0); + public function get($key,&$flags=null,&$cas=null); + public function getStats($type='',$slabid=0,$limit=100); + public function getExtendedStats($type='',$slabid=0,$limit=100); + public function setCompressThreshold($threshold,$minSavings=0.2); + public function delete($key,$exptime=0); + public function increment($key,$value=1,$defval=0,$exptime=0); + public function decrement($key,$value=1,$defval=0,$exptime=0); + public function close(); + public function flush($delay=0); + public function addServer($host,$tcpPort=11211,$udpPort=0,$persistent=true,$weight=1,$timeout=1,$retryInterval=15,$status=true); + public function connect($host,$tcpPort=11211,$udpPort=0,$persistent=true,$weight=1,$timeout=1,$retryInterval=15); + public function findServer($key); } } else { - throw new \Exception('LswMemcacheBundle does not support version '.$extension->getVersion().' of the memcached extension.'); + throw new \Exception('LswMemcacheBundle does not support version '.$extension->getVersion().' of the memcache extension.'); } diff --git a/Command/ClearCommand.php b/Command/ClearCommand.php index bfcfc3c..c859a04 100644 --- a/Command/ClearCommand.php +++ b/Command/ClearCommand.php @@ -31,10 +31,8 @@ protected function configure() ->setName('memcache:clear') ->setDescription('Invalidate all Memcache items') ->setDefinition(array( - new InputArgument('client', InputArgument::REQUIRED, 'The client'), - )) - ->addOption('prefix', null, InputOption::VALUE_REQUIRED, 'Only clears items with specific prefix') - ->addOption('regex', null, InputOption::VALUE_REQUIRED, 'Only clears items matching the expression'); + new InputArgument('pool', InputArgument::REQUIRED, 'The pool'), + )); } /** @@ -47,34 +45,19 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $client = $input->getArgument('client'); - $prefix = $input->getOption('prefix'); - $regex = $input->getOption('regex'); - - if(!empty($prefix) && !empty($regex)) { - throw new \InvalidArgumentException('you cannot filter by prefix and regex'); - } - - if(!empty($prefix)) { - $regex = '^'.$prefix.'(.*)'; - } + $pool = $input->getArgument('pool'); try { - $this->memcache = $this->getContainer()->get('memcache.'.$client); + $this->memcache = $this->getContainer()->get('memcache.'.$pool); - // flush/delete keys - if(empty($regex)) { - $output->writeln($this->memcache->flush()?'OK':'ERROR'); - } else { - $output->writeln($this->deleteByRegex($regex)?'OK':'ERROR'); - } + $output->writeln($this->memcache->flush()?'OK':'ERROR'); } catch (ServiceNotFoundException $e) { - $output->writeln("client '$client' is not found"); + $output->writeln("pool '$pool' is not found"); } } /** - * Choose the client + * Choose the pool * * @param InputInterface $input Input interface * @param OutputInterface $output Output interface @@ -84,44 +67,21 @@ protected function execute(InputInterface $input, OutputInterface $output) */ protected function interact(InputInterface $input, OutputInterface $output) { - if (!$input->getArgument('client')) { - $client = $this->getHelper('dialog')->askAndValidate( + if (!$input->getArgument('pool')) { + $pool = $this->getHelper('dialog')->askAndValidate( $output, - 'Please give the client:', - function($client) + 'Please give the pool:', + function($pool) { - if (empty($client)) { - throw new \Exception('client can not be empty'); + if (empty($pool)) { + throw new \Exception('pool can not be empty'); } - return $client; + return $pool; } ); - $input->setArgument('client', $client); - } - } - - /** - * delete keys by regular expression - * - * @param $regex - * @return bool|void - */ - private function deleteByRegex($regex) - { - // load keys - $keys = $this->memcache->getAllKeys(); - - if(!$keys) { - return false; + $input->setArgument('pool', $pool); } - - // filter keys - $deleteKeys = preg_grep('@'.$regex.'@', $keys); - // reset prefix - $this->memcache->setOption(\Memcached::OPT_PREFIX_KEY, ''); - // delete keys - return $this->memcache->deleteMulti($deleteKeys); } } diff --git a/Command/ItemsCommand.php b/Command/ItemsCommand.php deleted file mode 100644 index 4c4d098..0000000 --- a/Command/ItemsCommand.php +++ /dev/null @@ -1,141 +0,0 @@ -setName('memcache:items') - ->setDescription('Lists Memcache items') - ->setDefinition(array( - new InputArgument('client', InputArgument::REQUIRED, 'The client'), - )) - ->addOption('prefix', null, InputOption::VALUE_REQUIRED, 'Only lists items with specific prefix') - ->addOption('regex', null, InputOption::VALUE_REQUIRED, 'Only lists items matching the expression'); - } - - /** - * Execute the CLI task - * - * @param InputInterface $input Command input - * @param OutputInterface $output Command output - * - * @return void - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $client = $input->getArgument('client'); - $prefix = $input->getOption('prefix'); - $regex = $input->getOption('regex'); - - if(!empty($prefix) && !empty($regex)) { - throw new \InvalidArgumentException('you cannot filter by prefix and regex'); - } - - if(!empty($prefix)) { - $regex = '^'.$prefix.'(.*)'; - } - - try { - $this->memcache = $this->getContainer()->get('memcache.'.$client); - // reset prefix - $this->memcache->setOption(\Memcached::OPT_PREFIX_KEY, ''); - - // load keys - if(empty($regex)) { - $keys = $this->getAllKeys(); - } else { - $keys = $this->getKeysByRegex($regex); - } - - $output->writeln("".count($keys)." items found"); - - foreach ($keys as $key) { - // check if key has valid data - if($this->memcache->get($key)) { - $state = 'valid'; - } else { - $state = 'invalid'; - } - $output->writeln($key.' ['.$state.']'); - } - - } catch (ServiceNotFoundException $e) { - $output->writeln("client '$client' is not found"); - } - } - - /** - * Choose the client - * - * @param InputInterface $input Input interface - * @param OutputInterface $output Output interface - * - * @see Command - * @return mixed - */ - protected function interact(InputInterface $input, OutputInterface $output) - { - if (!$input->getArgument('client')) { - $client = $this->getHelper('dialog')->askAndValidate( - $output, - 'Please give the client:', - function($client) - { - if (empty($client)) { - throw new \Exception('client can not be empty'); - } - - return $client; - } - ); - $input->setArgument('client', $client); - } - } - - /** - * load all keys - * - * @return array - */ - private function getAllKeys() - { - $keys = $this->memcache->getAllKeys(); - return $keys ? $keys : array(); - } - - /** - * load keys filtered by regex - * - * @return array - */ - private function getKeysByRegex($regex) - { - $keys = $this->getAllKeys(); - return preg_grep('@'.$regex.'@', $keys); - } - -} diff --git a/Command/StatisticsCommand.php b/Command/StatisticsCommand.php index 6319a8e..e3fcc7a 100644 --- a/Command/StatisticsCommand.php +++ b/Command/StatisticsCommand.php @@ -10,7 +10,7 @@ use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; /** - * Provides a command-line interface for viewing cache client stats + * Provides a command-line interface for viewing cache pool stats * Based on Beryllium\CacheBundle by Kevin Boyd */ class StatisticsCommand extends ContainerAwareCommand @@ -27,7 +27,7 @@ protected function configure() ->setName('memcache:statistics') ->setDescription('Display Memcache statistics') ->setDefinition(array( - new InputArgument('client', InputArgument::REQUIRED, 'The client'), + new InputArgument('pool', InputArgument::REQUIRED, 'The pool'), )); } @@ -41,17 +41,17 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $client = $input->getArgument('client'); + $pool = $input->getArgument('pool'); try { - $memcache = $this->getContainer()->get('memcache.'.$client); + $memcache = $this->getContainer()->get('memcache.'.$pool); $output->writeln($this->formatStats($memcache->getStats())); } catch (ServiceNotFoundException $e) { - $output->writeln("client '$client' is not found"); + $output->writeln("pool '$pool' is not found"); } } /** - * Choose the client + * Choose the pool * * @param InputInterface $input Input interface * @param OutputInterface $output Output interface @@ -61,20 +61,20 @@ protected function execute(InputInterface $input, OutputInterface $output) */ protected function interact(InputInterface $input, OutputInterface $output) { - if (!$input->getArgument('client')) { - $client = $this->getHelper('dialog')->askAndValidate( + if (!$input->getArgument('pool')) { + $pool = $this->getHelper('dialog')->askAndValidate( $output, - 'Please give the client:', - function($client) + 'Please give the pool:', + function($pool) { - if (empty($client)) { - throw new \Exception('client can not be empty'); + if (empty($pool)) { + throw new \Exception('pool can not be empty'); } - return $client; + return $pool; } ); - $input->setArgument('client', $client); + $input->setArgument('pool', $pool); } } diff --git a/DataCollector/MemcacheDataCollector.php b/DataCollector/MemcacheDataCollector.php index 34d1ae7..01a1d98 100644 --- a/DataCollector/MemcacheDataCollector.php +++ b/DataCollector/MemcacheDataCollector.php @@ -16,7 +16,7 @@ */ class MemcacheDataCollector extends DataCollector { - private $clients; + private $pools; private $options; /** @@ -24,22 +24,22 @@ class MemcacheDataCollector extends DataCollector */ public function __construct() { - $this->clients = array(); + $this->pools = array(); $this->options = array(); } /** * Add a Memcache object to the collector * - * @param string $name Name of the Memcache client - * @param array $options Options for Memcache client + * @param string $name Name of the Memcache pool + * @param array $options Options for Memcache pool * @param LoggingMemcacheInterface $memcache Logging Memcache object * * @return void */ public function addClient($name, $options, LoggingMemcacheInterface $memcache) { - $this->clients[$name] = $memcache; + $this->pools[$name] = $memcache; $this->options[$name] = $options; } @@ -49,20 +49,20 @@ public function addClient($name, $options, LoggingMemcacheInterface $memcache) public function collect(Request $request, Response $response, \Exception $exception = null) { $empty = array('calls'=>array(),'config'=>array(),'options'=>array(),'statistics'=>array()); - $this->data = array('clients'=>$empty,'total'=>$empty); - foreach ($this->clients as $name => $memcache) { + $this->data = array('pools'=>$empty,'total'=>$empty); + foreach ($this->pools as $name => $memcache) { $calls = $memcache->getLoggedCalls(); - $this->data['clients']['calls'][$name] = $calls; - $this->data['clients']['options'][$name] = $this->options[$name]; + $this->data['pools']['calls'][$name] = $calls; + $this->data['pools']['options'][$name] = $this->options[$name]; } - $this->data['clients']['statistics'] = $this->calculateStatistics($this->data['clients']['calls']); - $this->data['total']['statistics'] = $this->calculateTotalStatistics($this->data['clients']['statistics']); + $this->data['pools']['statistics'] = $this->calculateStatistics($this->data['pools']['calls']); + $this->data['total']['statistics'] = $this->calculateTotalStatistics($this->data['pools']['statistics']); } private function calculateStatistics($calls) { $statistics = array(); - foreach ($this->data['clients']['calls'] as $name => $calls) { + foreach ($this->data['pools']['calls'] as $name => $calls) { $statistics[$name] = array('calls'=>0,'time'=>0,'reads'=>0,'hits'=>0,'misses'=>0,'writes'=>0); foreach ($calls as $call) { $statistics[$name]['calls'] += 1; @@ -74,7 +74,7 @@ private function calculateStatistics($calls) } else { $statistics[$name]['misses'] += 1; } - } elseif ($call->name == 'set') { + } elseif (in_array($call->name,array('set','add','cas','increment','decrement','delete'))) { $statistics[$name]['writes'] += 1; } } @@ -112,7 +112,7 @@ private function calculateTotalStatistics($statistics) */ public function getStatistics() { - return $this->data['clients']['statistics']; + return $this->data['pools']['statistics']; } /** @@ -133,7 +133,7 @@ public function getTotals() */ public function getCalls() { - return $this->data['clients']['calls']; + return $this->data['pools']['calls']; } /** @@ -143,7 +143,7 @@ public function getCalls() */ public function getOptions() { - return $this->data['clients']['options']; + return $this->data['pools']['options']; } /** diff --git a/DependencyInjection/Compiler/EnableSessionSupport.php b/DependencyInjection/Compiler/EnableSessionSupport.php index 40bc548..a80e062 100644 --- a/DependencyInjection/Compiler/EnableSessionSupport.php +++ b/DependencyInjection/Compiler/EnableSessionSupport.php @@ -18,13 +18,15 @@ public function process(ContainerBuilder $container) { // If there is no active session support, return if (!$container->hasAlias('session.storage')) { - return; + return; + } + // If auto_load is not enabled, return + if (!$container->getParameter('memcache.session_handler.auto_load')) { + return; } // If the memcache.session_handler service is loaded set the alias if ($container->hasDefinition('memcache.session_handler')) { - if (!$container->hasAlias('session.handler')) { - $container->setAlias('session.handler', 'memcache.session_handler'); - } - } + $container->setAlias('session.handler', 'memcache.session_handler'); + } } } \ No newline at end of file diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index bbbd000..2c090b3 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -8,7 +8,7 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; /** - * Defines the configuration options for the Memcached object + * Defines the configuration options for the Memcache object * Based on Emagister\MemcachedBundle by Christian Soronellas */ class Configuration implements ConfigurationInterface @@ -25,55 +25,77 @@ public function getConfigTreeBuilder() $rootNode ->append($this->addSessionSupportSection()) ->append($this->addDoctrineSection()) - ->append($this->addclientsSection()) + ->append($this->addClientsSection()) ; return $treeBuilder; } /** - * Configure the "lsw_memcache.clients" section + * Configure the "lsw_memcache.pools" section * * @return ArrayNodeDefinition */ - private function addclientsSection() + private function addClientsSection() { $tree = new TreeBuilder(); - $node = $tree->root('clients'); + $node = $tree->root('pools'); $node ->requiresAtLeastOneElement() ->useAttributeAsKey('name') ->prototype('array') ->children() - ->scalarNode('persistent_id') - ->defaultNull() - ->info('Specify to enable persistent connections. All clients with the same ID share connections.') - ->end() - ->arrayNode('hosts') + ->arrayNode('servers') ->requiresAtLeastOneElement() ->prototype('array') ->children() - ->scalarNode('dsn')->cannotBeEmpty()->isRequired()->end() - ->scalarNode('port') - ->cannotBeEmpty() + ->scalarNode('host') + ->cannotBeEmpty() + ->isRequired() + ->end() + ->scalarNode('tcp_port') ->defaultValue(11211) ->validate() ->ifTrue(function ($v) { return !is_numeric($v); }) - ->thenInvalid('host port must be numeric') + ->thenInvalid('port must be numeric') ->end() ->end() - ->scalarNode('weight') + ->scalarNode('udp_port') ->defaultValue(0) ->validate() ->ifTrue(function ($v) { return !is_numeric($v); }) - ->thenInvalid('host weight must be numeric') + ->thenInvalid('port must be numeric') + ->end() + ->end() + ->booleanNode('persistent') + ->defaultTrue() + ->end() + ->scalarNode('weight') + ->defaultValue(1) + ->validate() + ->ifTrue(function ($v) { return !is_numeric($v); }) + ->thenInvalid('weight must be numeric') ->end() ->end() - ->end() + ->scalarNode('timeout') + ->defaultValue(1) + ->validate() + ->ifTrue(function ($v) { return !is_numeric($v); }) + ->thenInvalid('timeout must be numeric') + ->end() + ->end() + ->scalarNode('retry_interval') + ->defaultValue(15) + ->validate() + ->ifTrue(function ($v) { return !is_numeric($v); }) + ->thenInvalid('retry_interval must be numeric') + ->end() + ->end() + ->end() ->end() ->end() - ->append($this->addMemcachedOptionsSection()) + ->append($this->addMemcacheOptionsSection()) ->end() ->end() ->end(); @@ -93,7 +115,8 @@ private function addSessionSupportSection() $node ->children() - ->scalarNode('client')->isRequired()->end() + ->scalarNode('pool')->isRequired()->end() + ->booleanNode('auto_load')->defaultTrue()->end() ->scalarNode('prefix')->end() ->scalarNode('ttl')->end() ->booleanNode('locking')->defaultTrue()->end() @@ -134,7 +157,7 @@ private function addDoctrineSection() ->arrayNode($type) ->canBeUnset() ->children() - ->scalarNode('client')->isRequired()->end() + ->scalarNode('pool')->isRequired()->end() ->scalarNode('prefix')->defaultValue('')->end() ->end() ->fixXmlConfig('entity_manager') @@ -165,102 +188,80 @@ private function addDoctrineSection() * * @return ArrayNodeDefinition */ - private function addMemcachedOptionsSection() + private function addMemcacheOptionsSection() { $tree = new TreeBuilder(); $node = $tree->root('options'); - // Memcached only configs + // Memcache only configs + $node ->children() - ->booleanNode('compression')->defaultFalse()->end() - ->scalarNode('serializer') - ->defaultValue('php') - ->validate() - ->ifNotInArray(array('php', 'json', 'igbinary')) - ->thenInvalid('serializer option must be: php, json or igbinary') - ->end() - ->end() - ->scalarNode('prefix_key')->defaultValue('')->end() - ->scalarNode('hash') - ->defaultValue('default') - ->validate() - ->ifNotInArray(array('default', 'md5', 'crc', 'fnv1_64', 'fnv1a_64', 'fnv1_32', 'fnv1a_32', 'hsieh', 'murmur')) - ->thenInvalid('hash option must be: default, md5, crc, fnv1_64, fnv1a_64, fnv1_32, fnv1a_32, hsieh, murmur') - ->end() - ->end() - ->scalarNode('distribution') - ->defaultValue('modula') - ->validate() - ->ifNotInArray(array('modula', 'consistent')) - ->thenInvalid('distribution option must be: modula, consistent') - ->end() - ->end() - ->booleanNode('libketama_compatible') - ->info('Set this to true when using consistent hashing') - ->defaultFalse() - ->end() - ->booleanNode('buffer_writes')->defaultFalse()->end() - ->booleanNode('binary_protocol')->defaultFalse()->end() - ->booleanNode('no_block')->defaultFalse()->end() - ->booleanNode('tcp_nodelay')->defaultFalse()->end() - ->scalarNode('socket_send_size') - ->defaultNull() - ->validate() - ->ifTrue(function($v) { return !is_numeric($v); }) - ->thenInvalid('socket_send_size option must be numeric') - ->end() - ->end() - ->scalarNode('socket_recv_size') - ->defaultNull() - ->validate() - ->ifTrue(function($v) { return !is_numeric($v); }) - ->thenInvalid('socket_recv_size option must be numeric') - ->end() - ->end() - ->scalarNode('connect_timeout') - ->defaultValue(1000) - ->validate() - ->ifTrue(function($v) { return !is_numeric($v); }) - ->thenInvalid('connect_timeout option must be numeric') - ->end() - ->end() - ->scalarNode('retry_timeout') - ->defaultValue(0) - ->validate() - ->ifTrue(function($v) { return !is_numeric($v); }) - ->thenInvalid('retry_timeout option must be numeric') - ->end() - ->end() - ->scalarNode('send_timeout') - ->defaultValue(0) - ->validate() - ->ifTrue(function($v) { return !is_numeric($v); }) - ->thenInvalid('send_timeout option must be numeric') - ->end() - ->end() - ->scalarNode('recv_timeout') - ->defaultValue(0) + ->booleanNode('allow_failover')->defaultTrue()->end() + ->scalarNode('max_failover_attempts') + ->defaultValue(20) + ->validate() + ->ifTrue(function($v) { return !is_numeric($v); }) + ->thenInvalid('max_failover_attempts option must be numeric') + ->end() + ->end() + ->scalarNode('default_port') + ->defaultValue(11211) + ->validate() + ->ifTrue(function($v) { return !is_numeric($v); }) + ->thenInvalid('default_port option must be numeric') + ->end() + ->end() + ->scalarNode('chunk_size') + ->defaultValue(32768) + ->validate() + ->ifTrue(function($v) { return !is_numeric($v); }) + ->thenInvalid('chunk_size option must be numeric') + ->end() + ->end() + ->scalarNode('protocol') + ->defaultValue('ascii') ->validate() - ->ifTrue(function($v) { return !is_numeric($v); }) - ->thenInvalid('recv_timeout option must be numeric') + ->ifNotInArray(array('ascii', 'binary')) + ->thenInvalid('protocol option must be: ascii or binary') ->end() - ->end() - ->scalarNode('poll_timeout') - ->defaultValue(1000) + ->end() + ->scalarNode('hash_strategy') + ->defaultValue('consistent') ->validate() - ->ifTrue(function($v) { return !is_numeric($v); }) - ->thenInvalid('poll_timeout option must be numeric') + ->ifNotInArray(array('standard', 'consistent')) + ->thenInvalid('hash_strategy option must be: standard or consistent') ->end() - ->end() - ->booleanNode('cache_lookups')->defaultFalse()->end() - ->scalarNode('server_failure_limit') - ->defaultValue(0) + ->end() + ->scalarNode('hash_function') + ->defaultValue('crc32') ->validate() - ->ifTrue(function($v) { return !is_numeric($v); }) - ->thenInvalid('server_failure_limit option must be numeric') + ->ifNotInArray(array('crc32', 'fnv')) + ->thenInvalid('hash_function option must be: crc32 or fnv') ->end() - ->end() + ->end() + ->booleanNode('redundancy')->defaultTrue()->end() + ->scalarNode('session_redundancy') + ->defaultValue(2) + ->validate() + ->ifTrue(function($v) { return !is_numeric($v); }) + ->thenInvalid('session_redundancy option must be numeric') + ->end() + ->end() + ->scalarNode('compress_threshold') + ->defaultValue(20000) + ->validate() + ->ifTrue(function($v) { return !is_numeric($v); }) + ->thenInvalid('compress_threshold option must be numeric') + ->end() + ->end() + ->scalarNode('lock_timeout') + ->defaultValue(15) + ->validate() + ->ifTrue(function($v) { return !is_numeric($v); }) + ->thenInvalid('lock_timeout option must be numeric') + ->end() + ->end() ->end() ->end(); diff --git a/DependencyInjection/LswMemcacheExtension.php b/DependencyInjection/LswMemcacheExtension.php index 961cbed..ea734d9 100644 --- a/DependencyInjection/LswMemcacheExtension.php +++ b/DependencyInjection/LswMemcacheExtension.php @@ -12,7 +12,7 @@ use Symfony\Component\DependencyInjection\Definition; /** - * Applies the configuration for the Memcached object + * Applies the configuration for the Memcache object * Based on Emagister\MemcachedBundle by Christian Soronellas */ class LswMemcacheExtension extends Extension @@ -37,13 +37,13 @@ public function load(array $configs, ContainerBuilder $container) if (isset($config['doctrine'])) { $this->loadDoctrine($config, $container); } - if (isset($config['clients'])) { - $this->addClients($config['clients'], $container); + if (isset($config['pools'])) { + $this->addClients($config['pools'], $container); } } /** - * Given a handler (memcache/memcached) enables session support + * Enables session support using Memcache based on the configuration * * @param string $config Configuration for bundle * @param ContainerBuilder $container Service container @@ -52,13 +52,13 @@ public function load(array $configs, ContainerBuilder $container) */ private function enableSessionSupport($config, ContainerBuilder $container) { - // make sure the client is specified and it exists - $client = $config['session']['client']; - if (null === $client) { + // make sure the pool is specified and it exists + $pool = $config['session']['pool']; + if (null === $pool) { return; } - if (!isset($config['clients']) || !isset($config['clients'][$client])) { - throw new \LogicException(sprintf('The client "%s" does not exist! Cannot enable the session support!', $client)); + if (!isset($config['pools']) || !isset($config['pools'][$pool])) { + throw new \LogicException(sprintf('The pool "%s" does not exist! Cannot enable the session support!', $pool)); } // calculate options $sessionOptions = $container->getParameter('session.storage.options'); @@ -74,13 +74,15 @@ private function enableSessionSupport($config, ContainerBuilder $container) $options['locking'] = $config['session']['locking']; $options['spin_lock_wait'] = $config['session']['spin_lock_wait']; $options['lock_max_wait'] = $config['session']['lock_max_wait']; + // set the auto_load parameter + $container->setParameter('memcache.session_handler.auto_load', $config['session']['auto_load']); // load the session handler $definition = new Definition($container->getParameter('memcache.session_handler.class')); $container->setDefinition('memcache.session_handler', $definition); $definition - ->addArgument(new Reference(sprintf('memcache.%s', $client))) + ->addArgument(new Reference(sprintf('memcache.%s', $pool))) ->addArgument($options); - $this->addClassesToCompile(array($definition->getClass())); + $this->addClassesToCompile(array($definition->getClass())); } /** @@ -92,11 +94,11 @@ private function enableSessionSupport($config, ContainerBuilder $container) protected function loadDoctrine(array $config, ContainerBuilder $container) { foreach ($config['doctrine'] as $name => $cache) { - $client = new Reference(sprintf('memcache.%s', $cache['client'])); + $pool = new Reference(sprintf('memcache.%s', $cache['pool'])); foreach ($cache['entity_managers'] as $em) { $def = new Definition($container->getParameter('memcache.doctrine_cache.class')); $def->setScope(ContainerInterface::SCOPE_CONTAINER); - $def->addMethodCall('setMemcached', array($client)); + $def->addMethodCall('setMemcache', array($pool)); if ($cache['prefix']) { $def->addMethodCall('setPrefix', array($cache['prefix'])); } @@ -105,7 +107,7 @@ protected function loadDoctrine(array $config, ContainerBuilder $container) foreach ($cache['document_managers'] as $dm) { $def = new Definition($container->getParameter('memcache.doctrine_cache.class')); $def->setScope(ContainerInterface::SCOPE_CONTAINER); - $def->addMethodCall('setMemcached', array($client)); + $def->addMethodCall('setMemcache', array($pool)); if ($cache['prefix']) { $def->addMethodCall('setPrefix', array($cache['prefix'])); } @@ -115,22 +117,22 @@ protected function loadDoctrine(array $config, ContainerBuilder $container) } /** - * Adds memcache/memcached clients to the service contaienr + * Adds memcache/memcache pools to the service contaienr * - * @param array $clients Array of client configurations + * @param array $pools Array of pool configurations * @param ContainerBuilder $container Service container * * @throws \LogicException */ - private function addClients(array $clients, ContainerBuilder $container) + private function addClients(array $pools, ContainerBuilder $container) { - foreach ($clients as $client => $memcachedConfig) { - $this->newMemcachedClient($client, $memcachedConfig, $container); + foreach ($pools as $pool => $memcacheConfig) { + $this->newMemcacheClient($pool, $memcacheConfig, $container); } } /** - * Creates a new Memcached definition + * Creates a new Memcache definition * * @param string $name Client name * @param array $config Client configuration @@ -138,61 +140,43 @@ private function addClients(array $clients, ContainerBuilder $container) * * @throws \LogicException */ - private function newMemcachedClient($name, array $config, ContainerBuilder $container) + private function newMemcacheClient($name, array $config, ContainerBuilder $container) { - // Check if the Memcached extension is loaded - if (!extension_loaded('memcached')) { - throw new \LogicException('Memcached extension is not loaded! To configure memcached clients it MUST be loaded!'); - } - - $memcached = new Definition('Lsw\MemcacheBundle\Cache\AntiDogPileMemcache'); - $memcached->addArgument(new Parameter('kernel.debug')); - - // Check if it has to be persistent - if (isset($config['persistent_id'])) { - $memcached->addArgument($config['persistent_id']); - } - - // Add servers to the memcached client - $servers = array(); - foreach ($config['hosts'] as $host) { - $servers[] = array( - $host['dsn'], - $host['port'], - $host['weight'] + // Check if the Memcache extension is loaded + if (!extension_loaded('memcache')) { + throw new \LogicException('Memcache extension is not loaded! To configure pools it MUST be loaded!'); + } + + $memcache = new Definition('Lsw\MemcacheBundle\Cache\AntiDogPileMemcache'); + $memcache->addArgument(new Parameter('kernel.debug')); + + // Add servers to the memcache pool + foreach ($config['servers'] as $s) { + $server = array( + $s['host'], + $s['tcp_port'], + $s['udp_port'], + $s['persistent'], + $s['weight'], + $s['timeout'], + $s['retry_interval'] ); + $memcache->addMethodCall('addServer', $server); } - $memcached->addMethodCall('addServers', array($servers)); - - // Get default memcached options + + // Get default memcache options $options = $container->getParameter('memcache.default_options'); - // Add overriden options + // Set overriden options if (isset($config['options'])) { foreach ($options as $key => $value) { if (isset($config['options'][$key])) { - if ($key == 'serializer') { - // serializer option needs to be supported and is a constant - if ($value != 'php' && !constant('Memcached::HAVE_' . strtoupper($value))) { - throw new \LogicException("Invalid serializer specified for Memcached: $value"); - } - $newValue = constant('Memcached::SERIALIZER_' . strtoupper($value)); - } elseif ($key == 'distribution') { - // distribution is defined as a constant - $newValue = constant('Memcached::DISTRIBUTION_' . strtoupper($value)); - } else { - $newValue = $config['options'][$key]; - } - if ($config['options'][$key]!=$value) { - // not default, add method call and update options - $constant = 'Memcached::OPT_'.strtoupper($key); - $memcached->addMethodCall('setOption', array(constant($constant), $newValue)); - $options[$key] = $newValue; - } - + $options[$key] = $config['options'][$key]; } } } + + $memcache->addArgument($options); // Make sure that config values are human readable foreach ($options as $key => $value) { @@ -201,7 +185,7 @@ private function newMemcachedClient($name, array $config, ContainerBuilder $cont // Add the service to the container $serviceName = sprintf('memcache.%s', $name); - $container->setDefinition($serviceName, $memcached); + $container->setDefinition($serviceName, $memcache); // Add the service to the data collector if ($container->hasDefinition('memcache.data_collector')) { $definition = $container->getDefinition('memcache.data_collector'); diff --git a/Doctrine/Cache/MemcachedCache.php b/Doctrine/Cache/MemcachedCache.php index 4d55141..83f6317 100644 --- a/Doctrine/Cache/MemcachedCache.php +++ b/Doctrine/Cache/MemcachedCache.php @@ -1,45 +1,45 @@ memcached = $memcached; + $this->memcache = $memcache; } /** - * Gets the memcached instance used by the cache. + * Gets the memcache instance used by the cache. * - * @return Memcached + * @return Memcache */ - public function getMemcached() + public function getMemcache() { - return $this->memcached; + return $this->memcache; } /** @@ -67,7 +67,7 @@ public function getPrefix() */ protected function doFetch($id) { - return $this->memcached->get($this->prefix.$id); + return $this->memcache->get($this->prefix.$id); } /** @@ -75,7 +75,7 @@ protected function doFetch($id) */ protected function doContains($id) { - return (bool) $this->memcached->get($this->prefix.$id); + return (bool) $this->memcache->get($this->prefix.$id); } /** @@ -86,7 +86,7 @@ protected function doSave($id, $data, $lifeTime = 0) if ($lifeTime > 30 * 24 * 3600) { $lifeTime = time() + $lifeTime; } - return $this->memcached->set($this->prefix.$id, $data, (int) $lifeTime); + return $this->memcache->set($this->prefix.$id, $data, null, (int) $lifeTime); } /** @@ -94,7 +94,7 @@ protected function doSave($id, $data, $lifeTime = 0) */ protected function doDelete($id) { - return $this->memcached->delete($this->prefix.$id); + return $this->memcache->delete($this->prefix.$id); } /** @@ -102,7 +102,7 @@ protected function doDelete($id) */ protected function doFlush() { - return $this->memcached->flush(); + return $this->memcache->flush(); } /** @@ -110,7 +110,7 @@ protected function doFlush() */ protected function doGetStats() { - $stats = $this->memcached->getStats(); + $stats = $this->memcache->getStats(); return array( Cache::STATS_HITS => $stats['get_hits'], Cache::STATS_MISSES => $stats['get_misses'], diff --git a/README.md b/README.md index 01958a0..bffc7d3 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,10 @@ It has full Web Debug Toolbar integration that allows you to analyze and debug t ### Requirements - PHP 5.3.10 or higher -- php-memcached 1.0.2, 2.0.1 or 2.1.0 (this is the PHP "memcached" extension that uses "libmemcached") - -NB: php-memcached 2.2.x gives runtime notices and should be avoided! - -NB: Unlike the PHP "memcache" extension, the PHP "memcached" extension is not (yet) included in the PHP Windows binaries. +- php-memcache 3.0.8 or higher +- memcached 1.4 or higher +NB: This bundle no longer uses the PHP "memcached" extension that uses "libmemcached", see "Considerations". ### Installation @@ -54,16 +52,16 @@ Configure the bundle by adding the following to app/config/config.yml': ```yml lsw_memcache: session: - client: default - clients: + pool: default + pools: default: - hosts: - - { dsn: localhost, port: 11211 } + servers: + - { host: localhost, port: 11211 } ``` Install the following dependencies (in Debian based systems using 'apt'): - apt-get install memcached php5-memcached + apt-get install memcached php5-memcache Do not forget to restart you web server after adding the Memcache module. Now the Memcache information should show up with a little double arrow (fast-forward) icon in your debug toolbar. @@ -72,66 +70,60 @@ information should show up with a little double arrow (fast-forward) icon in you When you want to use the cache from the controller you can simply call: - $this->get('memcache.default')->set('someKey', 'someValue', $timeToLive); + $this->get('memcache.default')->set('someKey', 'someValue', 0, $timeToLive); $this->get('memcache.default')->get('someKey'); The above example shows how to store value 'someValue' under key 'someKey' for a maximum of $timeToLive -seconds. In the second line the value is retrieved from Memcache. If the key can not be found or the -specified number of seconds have passed the 'get' function returns the value 'false'. +seconds (the 0 parameter are the 'flags'). In the second line the value is retrieved from Memcache. +If the key can not be found or the specified number of seconds have passed the 'get' function returns +the value 'false'. ### Configuration -Below you can see a full configuration for this bundle. +Below you can see an example configuration for this bundle. ```yml lsw_memcache: - clients: + pools: default: - persistent_id: default # Do NOT use this, see known issues - hosts: - - { dsn: 10.0.0.1, port: 11211, weight: 15 } - - { dsn: 10.0.0.2, port: 11211, weight: 30 } + servers: + - { host: 10.0.0.1, tcp_port: 11211, weight: 15 } + - { host: 10.0.0.2, tcp_port: 11211, weight: 30 } options: - compression: true - serializer: json - prefix_key: "" - hash: default - distribution: consistent - libketama_compatible: true - buffer_writes: true - binary_protocol: true - no_block: true - tcp_nodelay: false - socket_send_size: 4096 - socket_recv_size: 4096 - connect_timeout: 1000 - retry_timeout: 0 - send_timeout: 0 - recv_timeout: 0 - poll_timeout: 1000 - cache_lookups: false - server_failure_limit: 0 + allow_failover: true + max_failover_attempts: 20 + default_port: 11211 + chunk_size: 32768 + protocol: ascii + hash_strategy: consistent + hash_function: crc32 + redundancy: true + session_redundancy: 2 + compress_threshold: 20000 + lock_timeout: 15 sessions: - hosts: - - { dsn: localhost, port: 11212 } + servers: + - { host: localhost, tcp_port: 11212 } ``` ### Session Support ### This bundle also provides support for storing session data on Memcache servers. To enable session support -you will have to enable it through the ```session``` key. Note that the only required subkey of -the session support is ```client``` (a valid client). You can also specify a key prefix and an ttl. +you will have to enable it through the ```session``` key (```auto_load``` is true by default). Note that the only +required subkey of the session support is ```pool``` (a valid pool). You can also specify a key ```prefix``` +and a ```ttl```. ```yml lsw_memcache: session: - client: sessions + pool: sessions + auto_load: true prefix: "session_" ttl: 7200 locking: true spin_lock_wait: 150000 - # clients + # pools ``` Note that the session locking is enabled by default and the default spin lock is set to poll every 150 milliseconds (150000 microseconds). @@ -141,32 +133,32 @@ Note that the session locking is enabled by default and the default spin lock is This bundle also provides support for Doctrine caching on Memcache servers. To enable Doctrine caching you will have to enable it through the ```doctrine``` key. Note that you can specify all three kinds of Doctrine caching: 'metadata', 'result' and 'query'. The required keys within those subkeys are both -```client``` (a valid client) and ```entity_manager``` (normally: default). You can also specify a prefix. +```pool``` (a valid pool) and ```entity_manager``` (normally: default). You can also specify a ```prefix```. ```yml lsw_memcache: doctrine: metadata_cache: - client: default + pool: default entity_manager: default # the name of your entity_manager connection document_manager: default # the name of your document_manager connection result_cache: - client: default + pool: default entity_manager: [default, read] # you may specify multiple entity_managers prefix: "result_" # you may specify a prefix for the entries query_cache: - client: default + pool: default entity_manager: default - # clients + # pools ``` ### ADP: Anti Dog Pile Let us examine a high traffic website case and see how Memcache behaves: -Your cache is stored for 90 minutes. It takes about 3 second to calculate the cache value and 1 ms second to read from cache the cache value. You have about 5000 requests per second and that the value is cached. You get 5000 requests per second taking about 5000 ms to read the values from cache. You might think that that is not possible since 5000 > 1000, but that depends on the number of worker processes on your web server Let's say it is about 100 workers (under high load) with 75 threads each. Your web requests take about 20 ms each. Whenever the cache invalidates (after 90 minutes), during 3 seconds, there will be 15000 requests getting a cache miss. All the threads getting a miss will start to calculate the cache value (because they don't know the other threads are doing the same). This means that during (almost) 3 seconds the server wont answer a single request, but the requests keep coming in. Since each worker has 75 threads (holding 100 x 75 connections), the amount of workers has to go up to be able to process them. +Your cache is stored for 90 minutes. It takes about 3 second to calculate the cache value and 1 ms second to read from cache the cache value. You have about 5000 requests per second and that the value is cached. You get 5000 requests per second taking about 5000 ms to read the values from cache. You might think that that is not possible since 5000 > 1000, but that depends on the number of worker processes on your web server. Let's say it is about 100 workers (under high load) with 75 threads each. Your web requests take about 20 ms each. Whenever the cache invalidates (after 90 minutes), during 3 seconds, there will be 15000 requests getting a cache miss. All the threads getting a miss will start to calculate the cache value (because they don't know the other threads are doing the same). This means that during (almost) 3 seconds the server wont answer a single request, but the requests keep coming in. Since each worker has 75 threads (holding 100 x 75 connections), the amount of workers has to go up to be able to process them. -The heavy forking will cause extra CPU usage and the each worker will use extra RAM. This unexpected increase in RAM and CPU is called the 'dog pile' effect or 'stampeding herd' and is very unwelcome during peak hours on a web service. +The heavy forking will cause extra CPU usage and the each worker will use extra RAM. This unexpected increase in RAM and CPU is called the 'dog pile' effect or 'stampeding herd' or 'thundering herd' and is very unwelcome during peak hours on a web service. There is a solution: we serve the old cache entries while calculating the new value and by using an atomic read and write operation we can make sure only one thread will receive a cache miss when the content is invalidated. The algorithm is implemented in AntiDogPileMemcache class in LswMemcacheBundle. It provides the getAdp() and setAdp() functions that can be used as replacements for the normal get and set. @@ -180,8 +172,9 @@ Please note: ### Considerations -LswMemcacheBundle uses the 'memcached' PHP extension (client) not the older 'memcache' PHP extension. -For a comparison of the available clients see: http://code.google.com/p/memcached/wiki/PHPClientComparison +LswMemcacheBundle uses the 'memcache' PHP extension (memcached client) and not the libmemcache based 'memcached' PHP extension. + +Major version 1 of this bundle used the other extension. In major version 2 of this bundle the full featured version 3.0.8 of PECL "memcache" (without the 'd') was chosen, due to it's complete feature set and good design and support. ### Known issues @@ -190,9 +183,6 @@ The collect call of the memcache data collector is executed before the rendering and therefor also before the session write is executed. This causes the session writes not to show up in the Web Debug Toolbar. -Enabling persistent connections (setting "persistent_id") is known to crash php5 (core dump) on some systems. -Use with caution: it is strongly recommended to leave out "persistent_id" from the configuration. - ### Credits Doctrine support is based on the implementation in SncRedisBundle: @@ -216,8 +206,3 @@ https://github.com/beryllium/CacheBundle by Kevin Boyd ### License This bundle is under the MIT license. - -The "fast-forward" icon in the web debug toolbar is part of the Picas icon set (official website: http://www.picasicons.com). -The icon is licensed and may only be used to identifying the LswMemcacheBundle in the Symfony2 web debug toolbar. -All ownership and copyright of this icon remain the property of Rok Benedik. - diff --git a/Resources/codegen/generate.php b/Resources/codegen/generate.php index 8d43564..a72e67e 100644 --- a/Resources/codegen/generate.php +++ b/Resources/codegen/generate.php @@ -1,16 +1,16 @@ getVersion()=='$version') {\n"; - $lines = file($dir.DIRECTORY_SEPARATOR.'memcached-api.php'); + $lines = file($dir.DIRECTORY_SEPARATOR.'memcache-api.php'); $class = 0; if ($interface) echo " interface MemcacheInterface {\n"; - else echo " class LoggingMemcache extends \\Memcached implements MemcacheInterface, LoggingMemcacheInterface {\n"; + else echo " class LoggingMemcache extends \\MemcachePool implements MemcacheInterface, LoggingMemcacheInterface {\n"; foreach ($lines as $line) { if (preg_match('/^\s*class/', $line)) $class++; if ($class != 1) continue; @@ -21,6 +21,7 @@ $arguments = $matches[2]; preg_match_all('/\$[a-zA-Z_0-9]+/', $arguments, $matches); $arguments = implode(',',$matches[0]); + $privates = str_replace('$', '$_', $arguments); if ($interface) { if ($function != '__construct') { echo str_replace(' {}', ';', $line); @@ -29,18 +30,11 @@ else { $line = str_replace(' {}', ' {', $line); if ($function == '__construct') $php = <<calls = array(); \$this->logging = \$logging; - if (\$persistent_id) { - \$this->initialize = count(\$this->getServerList())==0; - } else { - \$this->initialize = true; - } - parent::__construct(\$persistent_id); } private \$calls; - private \$initialize; private \$logging; public function getLoggedCalls() { return \$this->calls; @@ -53,13 +47,18 @@ private function logCall(\$start, \$result) { END_OF_PHP; else $php = $line.<<logging) return parent::$function($arguments); - \$start = microtime(true); - \$name = '$function'; - \$arguments = array($arguments); - \$result = parent::$function($arguments); - \$time = microtime(true) - \$start; - \$this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + if (\$this->logging) { + \$start = microtime(true); + \$name = '$function'; + \$arguments = array($arguments); + } + list($privates) = array($arguments); + \$result = parent::$function($privates); + list($arguments) = array($privates); + if (\$this->logging) { + \$time = microtime(true) - \$start; + \$this->calls[] = (object) compact('start', 'time', 'name', 'arguments', 'result'); + } return \$result; } @@ -70,7 +69,7 @@ private function logCall(\$start, \$result) { echo " }\n"; echo "} else "; } - echo "{\n throw new \\Exception('LswMemcacheBundle does not support version '.\$extension->getVersion().' of the memcached extension.');\n}\n"; + echo "{\n throw new \\Exception('LswMemcacheBundle does not support version '.\$extension->getVersion().' of the memcache extension.');\n}\n"; if ($interface) file_put_contents('../../Cache/MemcacheInterface.php',ob_get_clean()); else file_put_contents('../../Cache/LoggingMemcache.php',ob_get_clean()); } \ No newline at end of file diff --git a/Resources/codegen/memcache-3.0.8/memcache-api.php b/Resources/codegen/memcache-3.0.8/memcache-api.php new file mode 100644 index 0000000..2a29988 --- /dev/null +++ b/Resources/codegen/memcache-3.0.8/memcache-api.php @@ -0,0 +1,111 @@ + + Memcache {{ collector.totals.calls }} {% if collector.totals.calls > 0 %} in {{ '%0.2f'|format(collector.totals.time * 1000) }} ms @@ -32,7 +32,7 @@ {% block menu %} - Memcache + Memcache Memcache @@ -45,7 +45,7 @@ {% block panel %}

Memcache

{% for name, calls in collector.calls %} -

Statistics for '{{ name }}'

+

Statistics for pool '{{ name }}'

{% for key, value in collector.statistics[name] %} @@ -61,7 +61,7 @@ {% endfor %}
-

Calls for '{{ name }}'

+

Calls for pool '{{ name }}'

{% if not collector.totals.calls %}

@@ -84,7 +84,7 @@ {% endif %} -

Options for '{{ name }}'

+

Options for pool '{{ name }}'

             {%- for key, value in collector.options[name] %}
                 {{- '%-25s'|format(key~':') }} {{ value }}{{ "\n" -}}
diff --git a/Session/Storage/LockingSessionHandler.php b/Session/Storage/LockingSessionHandler.php
index b4e7ac9..2cac0af 100644
--- a/Session/Storage/LockingSessionHandler.php
+++ b/Session/Storage/LockingSessionHandler.php
@@ -4,10 +4,10 @@
 /**
  * LockingSessionHandler.
  *
- * Memcached based session storage handler based on the Memcached class
- * provided by the PHP memcached extension with added locking support.
+ * Memcache based session storage handler based on the MemcachePool class
+ * provided by the PHP memcache extension with added locking support.
  *
- * @see http://php.net/memcached
+ * @see http://php.net/memcache
  *
  * @author Maurits van der Schee 
  */
@@ -45,9 +45,9 @@ class LockingSessionHandler implements \SessionHandlerInterface
     private $lockMaxWait;
 
     /**
-     * @var \Memcached Memcached driver.
+     * @var \MemcachePool Memcache driver.
      */
-    private $memcached;
+    private $memcache;
 
     /**
      * @var integer Time to live in seconds
@@ -63,17 +63,17 @@ class LockingSessionHandler implements \SessionHandlerInterface
      * Constructor.
      *
      * List of available options:
-     *  * prefix: The prefix to use for the memcached keys in order to avoid collision
+     *  * prefix: The prefix to use for the memcache keys in order to avoid collision
      *  * expiretime: The time to live in seconds
      *
-     * @param \Memcached $memcached A \Memcached instance
-     * @param array      $options   An associative array of Memcached options
+     * @param \MemcachePool $memcache  A \MemcachePool instance
+     * @param array         $options   An associative array of Memcache options
      *
      * @throws \InvalidArgumentException When unsupported options are passed
      */
-    public function __construct(\Memcached $memcached, array $options = array())
+    public function __construct(\MemcachePool $memcache, array $options = array())
     {
-        $this->memcached = $memcached;
+        $this->memcache = $memcache;
 
         if ($diff = array_diff(array_keys($options), array('prefix', 'expiretime', 'locking', 'spin_lock_wait', 'lock_max_wait'))) {
             throw new \InvalidArgumentException(sprintf(
@@ -108,15 +108,11 @@ private function lockSession($sessionId)
 
         $this->lockKey = $sessionId.'.lock';
         for ($i=0;$i<$attempts;$i++) {
-            $success = $this->memcached->add($this->prefix.$this->lockKey, '1', $this->lockMaxWait+1);
+            $success = $this->memcache->add($this->prefix.$this->lockKey, '1', null, $this->lockMaxWait+1);
             if ($success) {
                 $this->locked = true;
                 return true;
             }
-            $status = $this->memcached->getResultCode();
-            if ($status != \Memcached::RES_NOTSTORED && $status != \Memcached::RES_DATA_EXISTS) {
-                break;
-            }
             usleep($this->spinLockWait);
         }
 
@@ -125,7 +121,7 @@ private function lockSession($sessionId)
 
     private function unlockSession()
     {
-        $this->memcached->delete($this->prefix.$this->lockKey);
+        $this->memcache->delete($this->prefix.$this->lockKey);
         $this->locked = false;
     }
 
@@ -155,7 +151,7 @@ public function read($sessionId)
             }
         }
 
-        return $this->memcached->get($this->prefix.$sessionId) ?: '';
+        return $this->memcache->get($this->prefix.$sessionId) ?: '';
     }
 
     /**
@@ -171,7 +167,7 @@ public function write($sessionId, $data)
             }
         }
         
-        return $this->memcached->set($this->prefix.$sessionId, $data, time() + $this->ttl);
+        return $this->memcache->set($this->prefix.$sessionId, $data, null, $this->ttl);
     }
 
     /**
@@ -179,7 +175,7 @@ public function write($sessionId, $data)
      */
     public function destroy($sessionId)
     {
-        $this->memcached->delete($this->prefix.$sessionId);
+        $this->memcache->delete($this->prefix.$sessionId);
         $this->close();
         return true;
     }
@@ -189,7 +185,7 @@ public function destroy($sessionId)
      */
     public function gc($lifetime)
     {
-        // not required here because memcached will auto expire the records anyhow.
+        // not required here because memcache will auto expire the records anyhow.
         return true;
     }
 
diff --git a/Tests/Cache/AntiDogPileMemcacheTest.php b/Tests/Cache/AntiDogPileMemcacheTest.php
index 4b4a4a6..9fde309 100644
--- a/Tests/Cache/AntiDogPileMemcacheTest.php
+++ b/Tests/Cache/AntiDogPileMemcacheTest.php
@@ -14,7 +14,7 @@ class AntiDogPileMemcacheTest extends \PHPUnit_Framework_TestCase
 {
     public function testConstructAndInterfaces()
     {
-        $cache = new AntiDogPileMemcache('foo');
+        $cache = new AntiDogPileMemcache('foo',array());
 
         $this->assertInstanceOf('\Lsw\MemcacheBundle\Cache\LoggingMemcache', $cache);
     }
diff --git a/Tests/Cache/DogPileTest_.php b/Tests/Cache/DogPileTest_.php
index 00ea3fa..ba1ddaf 100644
--- a/Tests/Cache/DogPileTest_.php
+++ b/Tests/Cache/DogPileTest_.php
@@ -23,8 +23,8 @@ public function testDogPile()
         }
 
         $c = 10;
-        $m = new AntiDogPileMemcache(false);
-        $m->addServer('localhost', 11211);
+        $m = new AntiDogPileMemcache(false,array());
+        $m->addServer('localhost', 11212, 0);
         if ($t==1) {
             echo "THREAD | SECOND | STATUS\n";
         }
diff --git a/Tests/Cache/LoggingMemcacheTest.php b/Tests/Cache/LoggingMemcacheTest.php
index 00391ab..85069f4 100644
--- a/Tests/Cache/LoggingMemcacheTest.php
+++ b/Tests/Cache/LoggingMemcacheTest.php
@@ -14,9 +14,9 @@ class LoggingMemcacheTest extends \PHPUnit_Framework_TestCase
 {
     public function testConstructAndInterfaces()
     {
-        $cache = new LoggingMemcache('foo');
+        $cache = new LoggingMemcache('foo',array());
 
-        $this->assertInstanceOf('\Memcached', $cache);
+        $this->assertInstanceOf('\MemcachePool', $cache);
         $this->assertInstanceOf('\Lsw\MemcacheBundle\Cache\MemcacheInterface', $cache);
         $this->assertInstanceOf('\Lsw\MemcacheBundle\Cache\LoggingMemcacheInterface', $cache);
     }
@@ -28,7 +28,7 @@ public function testOpenPort()
 	
 	public function testGet()
     {
-    	$m = new LoggingMemcache(false);
+    	$m = new LoggingMemcache(false,array());
         $m->addServer('localhost', 11211);
         $m->set('key', 'value');
         $value = $m->get('key');
diff --git a/Tests/Cache/MemcacheInterfaceTest.php b/Tests/Cache/MemcacheInterfaceTest.php
index 9a7902f..f3e7fb4 100644
--- a/Tests/Cache/MemcacheInterfaceTest.php
+++ b/Tests/Cache/MemcacheInterfaceTest.php
@@ -28,42 +28,26 @@ function (\ReflectionMethod $method) {
     private function getDefaultMethods()
     {
         return array(
-            'get',
-            'getByKey',
-            'getMulti',
-            'getMultiByKey',
-            'getDelayed',
-            'getDelayedByKey',
-            'fetch',
-            'fetchAll',
-            'set',
-            'setByKey',
-            'setMulti',
-            'setMultiByKey',
-            'cas',
-            'casByKey',
-            'add',
-            'addByKey',
-            'append',
-            'appendByKey',
-            'prepend',
-            'prependByKey',
-            'replace',
-            'replaceByKey',
-            'delete',
-            'deleteByKey',
-            'increment',
-            'decrement',
-            'getOption',
-            'setOption',
-            'addServer',
-            'addServers',
-            'getServerList',
-            'getServerByKey',
-            'flush',
-            'getStats',
-            'getResultCode',
-            'getResultMessage',
+			'setFailureCallback',
+			'getServerStatus',
+			'getVersion',
+			'add',
+			'set',
+			'replace',
+			'cas',
+			'prepend',
+			'get',
+			'getStats',
+			'getExtendedStats',
+			'setCompressThreshold',
+			'delete',
+			'increment',
+			'decrement',
+			'close',
+			'flush',
+			'addServer',
+			'connect',
+			'findServer',
         );
     }
 }