From 8f90fa8b375321990b459448b0be6e46f9f95c70 Mon Sep 17 00:00:00 2001 From: cr1st1an Date: Wed, 30 Oct 2013 14:32:10 -0600 Subject: [PATCH 1/6] [fix] Session Memcached - Cookie key - Compress value 0 is valid - Expiry value 0 is valid - Actually setting expiry value --- src/EpiSession_Memcached.php | 157 ++++++++++++++++++----------------- 1 file changed, 79 insertions(+), 78 deletions(-) diff --git a/src/EpiSession_Memcached.php b/src/EpiSession_Memcached.php index 8ecdae1..e964fe7 100644 --- a/src/EpiSession_Memcached.php +++ b/src/EpiSession_Memcached.php @@ -1,83 +1,84 @@ host = !empty($params[0]) ? $params[0] : 'localhost'; + $this->port = !empty($params[1]) ? $params[1] : 11211; + $this->compress = isset($params[2]) ? $params[2] : 0; + $this->expiry = isset($params[3]) ? $params[3] : 3600; } - $this->host = !empty($params[0]) ? $params[0] : 'localhost'; - $this->port = !empty($params[1]) ? $params[1] : 11211;; - $this->compress = !empty($params[2]) ? $params[2] : 0;; - $this->expiry = !empty($params[3]) ? $params[3] : 3600; - } - - public function end() - { - if(!$this->connect()) - return; - - $this->memcached->delete($this->key); - $this->store = null; - setcookie(EpiSession::COOKIE, null, time()-86400); - } - - public function get($key = null) - { - if(!$this->connect() || empty($key) || !isset($this->store[$key])) - return false; - - return $this->store[$key]; - } - - public function getAll() - { - if(!$this->connect()) - return; - - return $this->memcached->get($this->key); - } - - public function set($key = null, $value = null) - { - if(!$this->connect() || empty($key)) - return false; - - $this->store[$key] = $value; - $this->memcached->set($this->key, $this->store); - return $value; - } - - private function connect($params = null) - { - if(self::$connected) - return true; - - if(class_exists('Memcached')) - { - $this->memcached = new Memcached; - if($this->memcached->addServer($this->host, $this->port)) - { - self::$connected = true; - $this->key = empty($key) ? $_COOKIE[EpiSession::COOKIE] : $key; - $this->store = $this->getAll(); - return true; - } - else - { - EpiException::raise(new EpiSessionMemcacheConnectException('Could not connect to memcache server')); - } + + public function end() { + if (!$this->connect()) + return; + + $this->memcached->delete($this->key); + $this->store = null; + setcookie(EpiSession::COOKIE, null, time() - 86400); + } + + public function get($key = null) { + if (!$this->connect() || empty($key) || !isset($this->store[$key])) + return false; + + return $this->store[$key]; + } + + public function getAll() { + if (!$this->connect()) + return; + + return $this->memcached->get($this->key); } - EpiException::raise(new EpiSessionMemcacheClientDneException('Could not connect to memcache server')); - } + + public function set($key = null, $value = null) { + if (!$this->connect() || empty($key)) + return false; + + $this->store[$key] = $value; + $this->memcached->set($this->key, $this->store, $this->expiry); + return $value; + } + + private function connect($params = null) { + if (self::$connected) + return true; + + if (class_exists('Memcached')) { + $this->memcached = new Memcached; + if ($this->memcached->addServer($this->host, $this->port)) { + self::$connected = true; + $this->key = $_COOKIE[EpiSession::COOKIE]; + $this->store = $this->getAll(); + return true; + } else { + EpiException::raise(new EpiSessionMemcacheConnectException('Could not connect to memcache server')); + } + } + EpiException::raise(new EpiSessionMemcacheClientDneException('Could not connect to memcache server')); + } + } -class EpiSessionMemcacheConnectException extends EpiException {} -class EpiSessionMemcacheClientDneException extends EpiException {} +class EpiSessionMemcacheConnectException extends EpiException { + +} + +class EpiSessionMemcacheClientDneException extends EpiException { + +} \ No newline at end of file From 7611fbac67790810c3e6b6ba88f8008d1472708f Mon Sep 17 00:00:00 2001 From: cr1st1an Date: Wed, 30 Oct 2013 14:36:40 -0600 Subject: [PATCH 2/6] [fix] Cache Memcached - Compress value 0 is valid - Expiry value 0 is valid --- src/EpiCache_Memcached.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/EpiCache_Memcached.php b/src/EpiCache_Memcached.php index 42e39c4..98022ff 100644 --- a/src/EpiCache_Memcached.php +++ b/src/EpiCache_Memcached.php @@ -10,9 +10,9 @@ class EpiCache_Memcached extends EpiCache public function __construct($params = array()) { $this->host = !empty($params[0]) ? $params[0] : 'localhost'; - $this->port = !empty($params[1]) ? $params[1] : 11211;; - $this->compress = !empty($params[2]) ? $params[2] : 0;; - $this->expiry = !empty($params[3]) ? $params[3] : 3600; + $this->port = !empty($params[1]) ? $params[1] : 11211; + $this->compress = isset($params[2]) ? $params[2] : 0; + $this->expiry = isset($params[3]) ? $params[3] : 3600; } public function delete($key, $timeout = 0) From 66eba99b1ca5498269a49a43c9a77332a3759904 Mon Sep 17 00:00:00 2001 From: cr1st1an Date: Wed, 30 Oct 2013 14:41:30 -0600 Subject: [PATCH 3/6] Revert 8f90fa8..7611fba This rolls back to commit 8f90fa8b375321990b459448b0be6e46f9f95c70. --- src/EpiCache_Memcached.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/EpiCache_Memcached.php b/src/EpiCache_Memcached.php index 98022ff..42e39c4 100644 --- a/src/EpiCache_Memcached.php +++ b/src/EpiCache_Memcached.php @@ -10,9 +10,9 @@ class EpiCache_Memcached extends EpiCache public function __construct($params = array()) { $this->host = !empty($params[0]) ? $params[0] : 'localhost'; - $this->port = !empty($params[1]) ? $params[1] : 11211; - $this->compress = isset($params[2]) ? $params[2] : 0; - $this->expiry = isset($params[3]) ? $params[3] : 3600; + $this->port = !empty($params[1]) ? $params[1] : 11211;; + $this->compress = !empty($params[2]) ? $params[2] : 0;; + $this->expiry = !empty($params[3]) ? $params[3] : 3600; } public function delete($key, $timeout = 0) From 545013a4860a141f874d99d56e90ee0bfcca912e Mon Sep 17 00:00:00 2001 From: cr1st1an Date: Wed, 30 Oct 2013 14:42:37 -0600 Subject: [PATCH 4/6] Revert 941b735..66eba99 This rolls back to commit 941b735f683bb4521c45c8961144ce3693083a87. --- src/EpiSession_Memcached.php | 157 +++++++++++++++++------------------ 1 file changed, 78 insertions(+), 79 deletions(-) diff --git a/src/EpiSession_Memcached.php b/src/EpiSession_Memcached.php index e964fe7..8ecdae1 100644 --- a/src/EpiSession_Memcached.php +++ b/src/EpiSession_Memcached.php @@ -1,84 +1,83 @@ host = !empty($params[0]) ? $params[0] : 'localhost'; - $this->port = !empty($params[1]) ? $params[1] : 11211; - $this->compress = isset($params[2]) ? $params[2] : 0; - $this->expiry = isset($params[3]) ? $params[3] : 3600; - } - - public function end() { - if (!$this->connect()) - return; - - $this->memcached->delete($this->key); - $this->store = null; - setcookie(EpiSession::COOKIE, null, time() - 86400); - } - - public function get($key = null) { - if (!$this->connect() || empty($key) || !isset($this->store[$key])) - return false; - - return $this->store[$key]; - } - - public function getAll() { - if (!$this->connect()) - return; - - return $this->memcached->get($this->key); +class EpiSession_Memcached implements EpiSessionInterface +{ + private static $connected = false; + private $key = null; + private $store= null; + + public function __construct($params = array()) + { + if(empty($_COOKIE[EpiSession::COOKIE])) + { + $cookieVal = md5(uniqid(rand(), true)); + setcookie(EpiSession::COOKIE, $cookieVal, time()+1209600, '/'); + $_COOKIE[EpiSession::COOKIE] = $cookieVal; } - - public function set($key = null, $value = null) { - if (!$this->connect() || empty($key)) - return false; - - $this->store[$key] = $value; - $this->memcached->set($this->key, $this->store, $this->expiry); - return $value; - } - - private function connect($params = null) { - if (self::$connected) - return true; - - if (class_exists('Memcached')) { - $this->memcached = new Memcached; - if ($this->memcached->addServer($this->host, $this->port)) { - self::$connected = true; - $this->key = $_COOKIE[EpiSession::COOKIE]; - $this->store = $this->getAll(); - return true; - } else { - EpiException::raise(new EpiSessionMemcacheConnectException('Could not connect to memcache server')); - } - } - EpiException::raise(new EpiSessionMemcacheClientDneException('Could not connect to memcache server')); - } - -} - -class EpiSessionMemcacheConnectException extends EpiException { + $this->host = !empty($params[0]) ? $params[0] : 'localhost'; + $this->port = !empty($params[1]) ? $params[1] : 11211;; + $this->compress = !empty($params[2]) ? $params[2] : 0;; + $this->expiry = !empty($params[3]) ? $params[3] : 3600; + } + + public function end() + { + if(!$this->connect()) + return; + + $this->memcached->delete($this->key); + $this->store = null; + setcookie(EpiSession::COOKIE, null, time()-86400); + } + + public function get($key = null) + { + if(!$this->connect() || empty($key) || !isset($this->store[$key])) + return false; + + return $this->store[$key]; + } + + public function getAll() + { + if(!$this->connect()) + return; + + return $this->memcached->get($this->key); + } + + public function set($key = null, $value = null) + { + if(!$this->connect() || empty($key)) + return false; + $this->store[$key] = $value; + $this->memcached->set($this->key, $this->store); + return $value; + } + + private function connect($params = null) + { + if(self::$connected) + return true; + + if(class_exists('Memcached')) + { + $this->memcached = new Memcached; + if($this->memcached->addServer($this->host, $this->port)) + { + self::$connected = true; + $this->key = empty($key) ? $_COOKIE[EpiSession::COOKIE] : $key; + $this->store = $this->getAll(); + return true; + } + else + { + EpiException::raise(new EpiSessionMemcacheConnectException('Could not connect to memcache server')); + } + } + EpiException::raise(new EpiSessionMemcacheClientDneException('Could not connect to memcache server')); + } } -class EpiSessionMemcacheClientDneException extends EpiException { - -} \ No newline at end of file +class EpiSessionMemcacheConnectException extends EpiException {} +class EpiSessionMemcacheClientDneException extends EpiException {} From 3b80e6bea1edc16639ffa55755b4dd062b072482 Mon Sep 17 00:00:00 2001 From: cr1st1an Date: Wed, 30 Oct 2013 14:43:41 -0600 Subject: [PATCH 5/6] Cache Memcached - Compress value 0 is valid - Expiry value 0 is valid --- src/EpiCache_Memcached.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/EpiCache_Memcached.php b/src/EpiCache_Memcached.php index 42e39c4..98022ff 100644 --- a/src/EpiCache_Memcached.php +++ b/src/EpiCache_Memcached.php @@ -10,9 +10,9 @@ class EpiCache_Memcached extends EpiCache public function __construct($params = array()) { $this->host = !empty($params[0]) ? $params[0] : 'localhost'; - $this->port = !empty($params[1]) ? $params[1] : 11211;; - $this->compress = !empty($params[2]) ? $params[2] : 0;; - $this->expiry = !empty($params[3]) ? $params[3] : 3600; + $this->port = !empty($params[1]) ? $params[1] : 11211; + $this->compress = isset($params[2]) ? $params[2] : 0; + $this->expiry = isset($params[3]) ? $params[3] : 3600; } public function delete($key, $timeout = 0) From a3eef5c385c5015aa6a7bba61bdcb15b81d5665c Mon Sep 17 00:00:00 2001 From: cr1st1an Date: Wed, 30 Oct 2013 14:48:40 -0600 Subject: [PATCH 6/6] Session Memcached - Compress value 0 is valid - Expiry value 0 is valid - Actually setting expiry value - Cookie key, to use same session --- src/EpiSession_Memcached.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/EpiSession_Memcached.php b/src/EpiSession_Memcached.php index 8ecdae1..fe324fe 100644 --- a/src/EpiSession_Memcached.php +++ b/src/EpiSession_Memcached.php @@ -2,21 +2,26 @@ class EpiSession_Memcached implements EpiSessionInterface { private static $connected = false; - private $key = null; - private $store= null; + private $memcached = false; + private $key = null; + private $store = null; + private $host = null; + private $port = null; + private $compress = null; + private $expiry = null; public function __construct($params = array()) { if(empty($_COOKIE[EpiSession::COOKIE])) { - $cookieVal = md5(uniqid(rand(), true)); - setcookie(EpiSession::COOKIE, $cookieVal, time()+1209600, '/'); - $_COOKIE[EpiSession::COOKIE] = $cookieVal; + $key = md5(uniqid(rand(), true)); + setcookie(EpiSession::COOKIE, $key, time() + 1209600, '/'); + $_COOKIE[EpiSession::COOKIE] = $key; } $this->host = !empty($params[0]) ? $params[0] : 'localhost'; - $this->port = !empty($params[1]) ? $params[1] : 11211;; - $this->compress = !empty($params[2]) ? $params[2] : 0;; - $this->expiry = !empty($params[3]) ? $params[3] : 3600; + $this->port = !empty($params[1]) ? $params[1] : 11211; + $this->compress = isset($params[2]) ? $params[2] : 0; + $this->expiry = isset($params[3]) ? $params[3] : 3600; } public function end() @@ -51,7 +56,7 @@ public function set($key = null, $value = null) return false; $this->store[$key] = $value; - $this->memcached->set($this->key, $this->store); + $this->memcached->set($this->key, $this->store, $this->expiry); return $value; } @@ -66,7 +71,7 @@ private function connect($params = null) if($this->memcached->addServer($this->host, $this->port)) { self::$connected = true; - $this->key = empty($key) ? $_COOKIE[EpiSession::COOKIE] : $key; + $this->key = $_COOKIE[EpiSession::COOKIE]; $this->store = $this->getAll(); return true; }