From d7287ec633577886e5f92543c2a610d4aaa93d53 Mon Sep 17 00:00:00 2001 From: ChrisTX Date: Sun, 21 Nov 2010 23:02:56 +0100 Subject: [feature/acm-wincache] Adding caching module for WinCache's User Cache. PHPBB3-9942 --- phpBB/includes/acm/acm_wincache.php | 84 +++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 phpBB/includes/acm/acm_wincache.php (limited to 'phpBB/includes/acm') diff --git a/phpBB/includes/acm/acm_wincache.php b/phpBB/includes/acm/acm_wincache.php new file mode 100644 index 0000000000..0501ab74c5 --- /dev/null +++ b/phpBB/includes/acm/acm_wincache.php @@ -0,0 +1,84 @@ +key_prefix . $var, $success); + + return ($success) ? $result : false; + } + + /** + * Store data in the cache + * + * @access protected + * @param string $var Cache key + * @param mixed $data Data to store + * @param int $ttl Time-to-live of cached data + * @return bool True if the operation succeeded + */ + function _write($var, $data, $ttl = 2592000) + { + return wincache_ucache_set($this->key_prefix . $var, $data, $ttl); + } + + /** + * Remove an item from the cache + * + * @access protected + * @param string $var Cache key + * @return bool True if the operation succeeded + */ + function _delete($var) + { + return wincache_ucache_delete($this->key_prefix . $var); + } +} -- cgit v1.2.1 From 5e97dd74c7a84869ac6f3b1bcd91122be8fddb50 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 27 Jan 2011 23:19:09 -0500 Subject: [ticket/10014] Clearly indicate fatal errors in file acm. If acm_file cannot open the cache file for writing, it prints a message to that effect and calls die(). The message itself does not indicate that it is a fatal error, and someone seeing the message might expect that inability to write to cache is not fatal. Make it clear that the error is fatal by printing the word "Fatal" before the message. PHPBB3-10014 --- phpBB/includes/acm/acm_file.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/acm') diff --git a/phpBB/includes/acm/acm_file.php b/phpBB/includes/acm/acm_file.php index 5c1876d006..524a28561e 100644 --- a/phpBB/includes/acm/acm_file.php +++ b/phpBB/includes/acm/acm_file.php @@ -88,11 +88,11 @@ class acm if (!phpbb_is_writable($this->cache_dir)) { // We need to use die() here, because else we may encounter an infinite loop (the message handler calls $cache->unload()) - die($this->cache_dir . ' is NOT writable.'); + die('Fatal: ' . $this->cache_dir . ' is NOT writable.'); exit; } - die('Not able to open ' . $this->cache_dir . 'data_global.' . $phpEx); + die('Fatal: Not able to open ' . $this->cache_dir . 'data_global.' . $phpEx); exit; } -- cgit v1.2.1 From fad7333e7266fe402e4a63f816b401c2f54b0c66 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 28 Mar 2011 21:08:53 +0800 Subject: [ticket/10110] Add Redis ACM backend PHPBB3-10110 --- phpBB/includes/acm/acm_redis.php | 142 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 phpBB/includes/acm/acm_redis.php (limited to 'phpBB/includes/acm') diff --git a/phpBB/includes/acm/acm_redis.php b/phpBB/includes/acm/acm_redis.php new file mode 100644 index 0000000000..3f0e590d0a --- /dev/null +++ b/phpBB/includes/acm/acm_redis.php @@ -0,0 +1,142 @@ +extension}] for the ACM module $acm_type.", E_USER_ERROR); + } + + $this->redis = new Redis(); + foreach (explode(',', PHPBB_ACM_REDIS) as $u) + { + $parts = explode('/', $u); + $this->redis->connect(trim($parts[0]), trim($parts[1])); + } + + if (defined('PHPBB_ACM_REDIS_PASSWORD')) + { + if (!$this->redis->auth(PHPBB_ACM_REDIS_PASSWORD)) + { + trigger_error("Incorrect password for the ACM module $acm_type.", E_USER_ERROR); + } + } + } + + /** + * Unload the cache resources + * + * @return void + */ + function unload() + { + parent::unload(); + + $this->redis->close(); + } + + /** + * Purge cache data + * + * @return void + */ + function purge() + { + $this->redis->flushDB(); + + parent::purge(); + } + + /** + * Fetch an item from the cache + * + * @access protected + * @param string $var Cache key + * @return mixed Cached data + */ + function _read($var) + { + return $this->redis->get($this->key_prefix . $var); + } + + /** + * Store data in the cache + * + * @access protected + * @param string $var Cache key + * @param mixed $data Data to store + * @param int $ttl Time-to-live of cached data + * @return bool True if the operation succeeded + */ + function _write($var, $data, $ttl = 2592000) + { + return $this->redis->setex($this->key_prefix . $var, $ttl, $data); + } + + /** + * Remove an item from the cache + * + * @access protected + * @param string $var Cache key + * @return bool True if the operation succeeded + */ + function _delete($var) + { + if ($this->redis->delete($this->key_prefix . $var) > 0) + { + return true; + } + return false; + } +} -- cgit v1.2.1 From f18d93756cad336db8299a2ab88ec3382efe171a Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 28 Mar 2011 23:09:32 +0800 Subject: [ticket/10110] Update comments with a link to the phpredis extension PHPBB3-10110 --- phpBB/includes/acm/acm_redis.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/acm') diff --git a/phpBB/includes/acm/acm_redis.php b/phpBB/includes/acm/acm_redis.php index 3f0e590d0a..b1739c0479 100644 --- a/phpBB/includes/acm/acm_redis.php +++ b/phpBB/includes/acm/acm_redis.php @@ -2,8 +2,7 @@ /** * * @package acm -* @version $Id$ -* @copyright (c) 2005, 2011 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ @@ -40,6 +39,10 @@ if (!defined('PHPBB_ACM_REDIS')) /** * ACM for Redis +* +* Compatible with the php extension phpredis available +* at https://github.com/nicolasff/phpredis +* * @package acm */ class acm extends acm_memory -- cgit v1.2.1 From 9891f5a8d2025aeec19c6b33de0d1a48dd92d211 Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 29 Mar 2011 15:54:28 +0800 Subject: [ticket/10110] Enable the serialization and add a constant for defined the database PHPBB3-10110 --- phpBB/includes/acm/acm_redis.php | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'phpBB/includes/acm') diff --git a/phpBB/includes/acm/acm_redis.php b/phpBB/includes/acm/acm_redis.php index b1739c0479..1c2b9c0c2f 100644 --- a/phpBB/includes/acm/acm_redis.php +++ b/phpBB/includes/acm/acm_redis.php @@ -48,7 +48,7 @@ if (!defined('PHPBB_ACM_REDIS')) class acm extends acm_memory { var $extension = 'redis'; - + var $redis; function acm() @@ -56,15 +56,10 @@ class acm extends acm_memory // Call the parent constructor parent::acm_memory(); - if (!extension_loaded('redis')) - { - trigger_error("Could not find required extension [{$this->extension}] for the ACM module $acm_type.", E_USER_ERROR); - } - $this->redis = new Redis(); - foreach (explode(',', PHPBB_ACM_REDIS) as $u) + foreach (explode(',', PHPBB_ACM_REDIS) as $server) { - $parts = explode('/', $u); + $parts = explode('/', $server); $this->redis->connect(trim($parts[0]), trim($parts[1])); } @@ -72,9 +67,24 @@ class acm extends acm_memory { if (!$this->redis->auth(PHPBB_ACM_REDIS_PASSWORD)) { + global $acm_type; + trigger_error("Incorrect password for the ACM module $acm_type.", E_USER_ERROR); } } + + $this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); + $this->redis->setOption(Redis::OPT_PREFIX, $this->key_prefix); + + if (defined('PHPBB_ACM_REDIS_DB')) + { + if (!$this->redis->select(PHPBB_ACM_REDIS_DB)) + { + global $acm_type; + + trigger_error("Incorrect database for the ACM module $acm_type.", E_USER_ERROR); + } + } } /** @@ -110,7 +120,7 @@ class acm extends acm_memory */ function _read($var) { - return $this->redis->get($this->key_prefix . $var); + return $this->redis->get($var); } /** @@ -124,7 +134,7 @@ class acm extends acm_memory */ function _write($var, $data, $ttl = 2592000) { - return $this->redis->setex($this->key_prefix . $var, $ttl, $data); + return $this->redis->setex($var, $ttl, $data); } /** @@ -136,7 +146,7 @@ class acm extends acm_memory */ function _delete($var) { - if ($this->redis->delete($this->key_prefix . $var) > 0) + if ($this->redis->delete($var) > 0) { return true; } -- cgit v1.2.1 From ddda094d3abd2e5971c77cc38993eefa3d0bdf3a Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 30 Mar 2011 17:55:53 +0800 Subject: [ticket/10110] Remove tab from empty lines PHPBB3-10110 --- phpBB/includes/acm/acm_redis.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/acm') diff --git a/phpBB/includes/acm/acm_redis.php b/phpBB/includes/acm/acm_redis.php index 1c2b9c0c2f..8954b9d0e7 100644 --- a/phpBB/includes/acm/acm_redis.php +++ b/phpBB/includes/acm/acm_redis.php @@ -48,7 +48,7 @@ if (!defined('PHPBB_ACM_REDIS')) class acm extends acm_memory { var $extension = 'redis'; - + var $redis; function acm() @@ -62,26 +62,26 @@ class acm extends acm_memory $parts = explode('/', $server); $this->redis->connect(trim($parts[0]), trim($parts[1])); } - + if (defined('PHPBB_ACM_REDIS_PASSWORD')) { if (!$this->redis->auth(PHPBB_ACM_REDIS_PASSWORD)) { global $acm_type; - + trigger_error("Incorrect password for the ACM module $acm_type.", E_USER_ERROR); } } - + $this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); $this->redis->setOption(Redis::OPT_PREFIX, $this->key_prefix); - + if (defined('PHPBB_ACM_REDIS_DB')) { if (!$this->redis->select(PHPBB_ACM_REDIS_DB)) { global $acm_type; - + trigger_error("Incorrect database for the ACM module $acm_type.", E_USER_ERROR); } } -- cgit v1.2.1 From b9f4240c103734b33aeab809312fcef8e32c396e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 11 Jun 2011 01:47:50 +0200 Subject: [ticket/10110] Remove multi-server syntax from Redis ACM. PHPBB3-10110 --- phpBB/includes/acm/acm_redis.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'phpBB/includes/acm') diff --git a/phpBB/includes/acm/acm_redis.php b/phpBB/includes/acm/acm_redis.php index 8954b9d0e7..41533eaacb 100644 --- a/phpBB/includes/acm/acm_redis.php +++ b/phpBB/includes/acm/acm_redis.php @@ -31,12 +31,6 @@ if (!defined('PHPBB_ACM_REDIS_HOST')) define('PHPBB_ACM_REDIS_HOST', 'localhost'); } -if (!defined('PHPBB_ACM_REDIS')) -{ - //can define multiple servers with host1/port1,host2/port2 format - define('PHPBB_ACM_REDIS', PHPBB_ACM_REDIS_HOST . '/' . PHPBB_ACM_REDIS_PORT); -} - /** * ACM for Redis * @@ -57,11 +51,7 @@ class acm extends acm_memory parent::acm_memory(); $this->redis = new Redis(); - foreach (explode(',', PHPBB_ACM_REDIS) as $server) - { - $parts = explode('/', $server); - $this->redis->connect(trim($parts[0]), trim($parts[1])); - } + $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT); if (defined('PHPBB_ACM_REDIS_PASSWORD')) { -- cgit v1.2.1