From f14f82775f0ff532ac48e3a739e221a8284d74b5 Mon Sep 17 00:00:00 2001 From: David M Date: Fri, 4 Jan 2008 18:56:42 +0000 Subject: ACMs? yep, ACMs... - Added support for APC, eAccelerator, xcache and memcache systems git-svn-id: file:///svn/phpbb/trunk@8302 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/acm/acm_memcache.php | 361 ++++++++++++++++++++++++++++++++++++ 1 file changed, 361 insertions(+) create mode 100644 phpBB/includes/acm/acm_memcache.php (limited to 'phpBB/includes/acm/acm_memcache.php') diff --git a/phpBB/includes/acm/acm_memcache.php b/phpBB/includes/acm/acm_memcache.php new file mode 100644 index 0000000000..4a1334a619 --- /dev/null +++ b/phpBB/includes/acm/acm_memcache.php @@ -0,0 +1,361 @@ +memcache = memcache_connect('localhost', 11211); + } + + /** + * Load global cache + */ + private function load() + { + global $phpEx; + + // grab the global cache + if ($this->vars = memcache_get($this->memcache, 'global')) + { + return true; + } + + return false; + } + + /** + * Unload cache object + */ + public function unload() + { + $this->save(); + unset($this->vars); + unset($this->sql_rowset); + unset($this->sql_row_pointer); + + $this->vars = array(); + $this->sql_rowset = array(); + $this->sql_row_pointer = array(); + } + + /** + * Save modified objects + */ + private function save() + { + if (!$this->is_modified) + { + return; + } + + memcache_set($this->memcache, 'global', $this->vars, 0, 2592000); + + $this->is_modified = false; + } + + /** + * Tidy cache + */ + public function tidy() + { + global $phpEx; + + // cache has auto GC, no need to have any code here :) + + set_config('cache_last_gc', time(), true); + } + + /** + * Get saved cache object + */ + public function get($var_name) + { + if ($var_name[0] === '_') + { + global $phpEx; + + return memcache_get($this->memcache, $var_name); + } + else + { + if (!sizeof($this->vars)) + { + $this->load(); + } + return (isset($this->vars[$var_name])) ? $this->vars[$var_name] : false; + } + } + + /** + * Put data into cache + */ + public function put($var_name, $var, $ttl = 31536000) + { + if ($var_name[0] === '_') + { + memcache_set($this->memcache, $var_name, $var, 0, $ttl); + } + else + { + $this->vars[$var_name] = $var; + $this->is_modified = true; + } + } + + /** + * Purge cache data + */ + public function purge() + { + // Purge all phpbb cache files + $dir = @opendir($this->cache_dir); + + if (!$dir) + { + return; + } + + while (($entry = readdir($dir)) !== false) + { + if (strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && strpos($entry, 'tpl_') !== 0) + { + continue; + } + + @unlink($this->cache_dir . $entry); + } + closedir($dir); + + memcache_flush($this->memcache); + + unset($this->vars); + unset($this->sql_rowset); + unset($this->sql_row_pointer); + + $this->vars = array(); + $this->var_expires = array(); + $this->sql_rowset = array(); + $this->sql_row_pointer = array(); + + $this->is_modified = false; + } + + /** + * Destroy cache data + */ + public function destroy($var_name, $table = '') + { + global $phpEx; + + if ($var_name === 'sql' && !empty($table)) + { + if (!is_array($table)) + { + $table = array($table); + } + + foreach ($table as $table_name) + { + // gives us the md5s that we want + $temp = memcache_get($this->memcache, 'sql_' . $table_name); + if ($temp === false) + { + continue; + } + + // delete each query ref + foreach ($temp as $md5_id => $void) + { + memcache_delete($this->memcache, 'sql_' . $md5_id); + } + + // delete the table ref + memcache_delete($this->memcache, 'sql_' . $table_name); + } + + return; + } + + if ($var_name[0] === '_') + { + memcache_delete($this->memcache, $var_name); + } + else if (isset($this->vars[$var_name])) + { + $this->is_modified = true; + unset($this->vars[$var_name]); + + // We save here to let the following cache hits succeed + $this->save(); + } + } + + /** + * Load cached sql query + */ + public function sql_load($query) + { + global $phpEx; + + // Remove extra spaces and tabs + $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); + $query_id = sizeof($this->sql_rowset); + + $temp = memcache_get($this->memcache, 'sql_' . md5($query)); + + if ($temp === false) + { + return false; + } + + $this->sql_rowset[$query_id] = $temp; + + $this->sql_row_pointer[$query_id] = 0; + + return $query_id; + } + + /** + * Save sql query + */ + public function sql_save($query, &$query_result, $ttl) + { + global $db, $phpEx; + + // Remove extra spaces and tabs + $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); + + // determine which tables this query belongs to: + + // grab all the FROM tables, avoid getting a LEFT JOIN + preg_match('/FROM \(?(\w+(?: (?!LEFT JOIN)\w+)?(?:, ?\w+(?: (?!LEFT JOIN)\w+)?)*)\)?/', $query, $regs); + $tables = array_map('trim', explode(',', $regs[1])); + + // now get the LEFT JOIN + preg_match_all('/LEFT JOIN\s+(\w+)(?: \w+)?/', $query, $result, PREG_PATTERN_ORDER); + $tables = array_merge($tables, $result[1]); + + $query_hash = md5($query); + + foreach ($tables as $table_name) + { + if (($pos = strpos($table_name, ' ')) !== false) + { + $table_name = substr($table_name, 0, $pos); + } + + $temp = memcache_get($this->memcache, 'sql_' . $table_name); + if ($temp === false) + { + $temp = array(); + } + $temp[$query_hash] = true; + memcache_set($this->memcache, 'sql_' . $table_name, $temp, 0, $ttl); + } + + // store them in the right place + $query_id = sizeof($this->sql_rowset); + $this->sql_rowset[$query_id] = array(); + $this->sql_row_pointer[$query_id] = 0; + + while ($row = $db->sql_fetchrow($query_result)) + { + $this->sql_rowset[$query_id][] = $row; + } + $db->sql_freeresult($query_result); + + memcache_set($this->memcache, 'sql_' . $query_hash, $this->sql_rowset[$query_id], 0, $ttl); + + $query_result = $query_id; + } + + /** + * Fetch row from cache (database) + */ + public function sql_fetchrow($query_id) + { + if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id])) + { + return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++]; + } + + return false; + } + + /** + * Fetch a field from the current row of a cached database result (database) + */ + public function sql_fetchfield($query_id, $field) + { + if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id])) + { + return (isset($this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field])) ? $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field] : false; + } + + return false; + } + + /** + * Seek a specific row in an a cached database result (database) + */ + public function sql_rowseek($rownum, $query_id) + { + if ($rownum >= sizeof($this->sql_rowset[$query_id])) + { + return false; + } + + $this->sql_row_pointer[$query_id] = $rownum; + return true; + } + + /** + * Free memory used for a cached database result (database) + */ + public function sql_freeresult($query_id) + { + if (!isset($this->sql_rowset[$query_id])) + { + return false; + } + + unset($this->sql_rowset[$query_id]); + unset($this->sql_row_pointer[$query_id]); + + return true; + } +} + +?> \ No newline at end of file -- cgit v1.2.1 From 7b262babcd5c862c3068b08da8bba5f48bd5f36a Mon Sep 17 00:00:00 2001 From: David M Date: Sun, 3 Feb 2008 10:19:04 +0000 Subject: Alright, this should give some improved performance :) This is the end of random seek access to rows. If you have a compelling reason as to why they should stay, contact me. Else, they are gone forevermore... The following API calls are deprecated: acm::sql_rowseek() -> no replacement $db->sql_fetchfield($field, $rownum = false, $query_id = false) -> $db->sql_fetchfield($field, $query_id = false) Initial tests show that phpBB3 over four percent of memory against phpBB3.1 on an empty board. So far so good :) Other cool things: db2, MS SQL ODBC and MS SQL 2005 all use less memory because they do not need to reference the last executed query to handle random access seeks :) P.S. The crazy people using SVN: please report any issues with the new way we itterate through caches, I do not want to miss anything :) git-svn-id: file:///svn/phpbb/trunk@8372 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/acm/acm_memcache.php | 36 ++++-------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) (limited to 'phpBB/includes/acm/acm_memcache.php') diff --git a/phpBB/includes/acm/acm_memcache.php b/phpBB/includes/acm/acm_memcache.php index 4a1334a619..fc17b04942 100644 --- a/phpBB/includes/acm/acm_memcache.php +++ b/phpBB/includes/acm/acm_memcache.php @@ -26,7 +26,6 @@ class acm private $is_modified = false; public $sql_rowset = array(); - private $sql_row_pointer = array(); public $cache_dir = ''; private $memcache; @@ -63,11 +62,9 @@ class acm $this->save(); unset($this->vars); unset($this->sql_rowset); - unset($this->sql_row_pointer); $this->vars = array(); $this->sql_rowset = array(); - $this->sql_row_pointer = array(); } /** @@ -162,12 +159,10 @@ class acm unset($this->vars); unset($this->sql_rowset); - unset($this->sql_row_pointer); $this->vars = array(); $this->var_expires = array(); $this->sql_rowset = array(); - $this->sql_row_pointer = array(); $this->is_modified = false; } @@ -242,7 +237,6 @@ class acm $this->sql_rowset[$query_id] = $temp; - $this->sql_row_pointer[$query_id] = 0; return $query_id; } @@ -288,7 +282,6 @@ class acm // store them in the right place $query_id = sizeof($this->sql_rowset); $this->sql_rowset[$query_id] = array(); - $this->sql_row_pointer[$query_id] = 0; while ($row = $db->sql_fetchrow($query_result)) { @@ -306,12 +299,9 @@ class acm */ public function sql_fetchrow($query_id) { - if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id])) - { - return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++]; - } + list(, $row) = each($this->sql_rowset[$query_id]); - return false; + return ($row !== NULL) ? $row : false; } /** @@ -319,26 +309,9 @@ class acm */ public function sql_fetchfield($query_id, $field) { - if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id])) - { - return (isset($this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field])) ? $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field] : false; - } - - return false; - } - - /** - * Seek a specific row in an a cached database result (database) - */ - public function sql_rowseek($rownum, $query_id) - { - if ($rownum >= sizeof($this->sql_rowset[$query_id])) - { - return false; - } + $row = current($this->sql_rowset[$query_id]); - $this->sql_row_pointer[$query_id] = $rownum; - return true; + return ($row !== false && isset($row[$field])) ? $row[$field] : false; } /** @@ -352,7 +325,6 @@ class acm } unset($this->sql_rowset[$query_id]); - unset($this->sql_row_pointer[$query_id]); return true; } -- cgit v1.2.1 From 2f4a618900e2c3b6ea14c68cbeb5897cd2ac1a04 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Thu, 29 May 2008 12:25:56 +0000 Subject: ok... i hope i haven't messed too much with the code and everything is still working. Changes: - Ascraeus now uses constants for the phpbb root path and the php extension. This ensures more security for external applications and modifications (no more overwriting of root path and extension possible through insecure mods and register globals enabled) as well as no more globalizing needed. - A second change implemented here is an additional short-hand-notation for append_sid(). It is allowed to omit the root path and extension now (for example calling append_sid('memberlist')) - in this case the root path and extension get added automatically. The hook is called after these are added. git-svn-id: file:///svn/phpbb/trunk@8572 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/acm/acm_memcache.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'phpBB/includes/acm/acm_memcache.php') diff --git a/phpBB/includes/acm/acm_memcache.php b/phpBB/includes/acm/acm_memcache.php index fc17b04942..bbb556f173 100644 --- a/phpBB/includes/acm/acm_memcache.php +++ b/phpBB/includes/acm/acm_memcache.php @@ -34,7 +34,6 @@ class acm */ function __construct() { - global $phpbb_root_path; $this->memcache = memcache_connect('localhost', 11211); } @@ -43,8 +42,6 @@ class acm */ private function load() { - global $phpEx; - // grab the global cache if ($this->vars = memcache_get($this->memcache, 'global')) { @@ -87,8 +84,6 @@ class acm */ public function tidy() { - global $phpEx; - // cache has auto GC, no need to have any code here :) set_config('cache_last_gc', time(), true); @@ -101,8 +96,6 @@ class acm { if ($var_name[0] === '_') { - global $phpEx; - return memcache_get($this->memcache, $var_name); } else @@ -172,8 +165,6 @@ class acm */ public function destroy($var_name, $table = '') { - global $phpEx; - if ($var_name === 'sql' && !empty($table)) { if (!is_array($table)) @@ -222,8 +213,6 @@ class acm */ public function sql_load($query) { - global $phpEx; - // Remove extra spaces and tabs $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); $query_id = sizeof($this->sql_rowset); @@ -246,7 +235,7 @@ class acm */ public function sql_save($query, &$query_result, $ttl) { - global $db, $phpEx; + global $db; // Remove extra spaces and tabs $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); -- cgit v1.2.1 From 794c5749696c9fa2595ed3a1d7c836a0d984e11c Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 22 Feb 2009 15:29:18 +0000 Subject: remove global and change $user-> to phpbb::$user-> git-svn-id: file:///svn/phpbb/trunk@9334 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/acm/acm_memcache.php | 178 +++++++++++++++++++++++++----------- 1 file changed, 124 insertions(+), 54 deletions(-) (limited to 'phpBB/includes/acm/acm_memcache.php') diff --git a/phpBB/includes/acm/acm_memcache.php b/phpBB/includes/acm/acm_memcache.php index bbb556f173..a89657b04e 100644 --- a/phpBB/includes/acm/acm_memcache.php +++ b/phpBB/includes/acm/acm_memcache.php @@ -1,10 +1,10 @@ cache_dir = $phpbb_root_path . 'cache/'; $this->memcache = memcache_connect('localhost', 11211); } /** * Load global cache */ - private function load() + function load() { // grab the global cache - if ($this->vars = memcache_get($this->memcache, 'global')) + $this->vars = memcache_get($this->memcache, 'global'); + + if ($this->vars !== false) { return true; } @@ -54,20 +59,22 @@ class acm /** * Unload cache object */ - public function unload() + function unload() { $this->save(); unset($this->vars); unset($this->sql_rowset); + unset($this->sql_row_pointer); $this->vars = array(); $this->sql_rowset = array(); + $this->sql_row_pointer = array(); } /** * Save modified objects */ - private function save() + function save() { if (!$this->is_modified) { @@ -82,7 +89,7 @@ class acm /** * Tidy cache */ - public function tidy() + function tidy() { // cache has auto GC, no need to have any code here :) @@ -92,28 +99,29 @@ class acm /** * Get saved cache object */ - public function get($var_name) + function get($var_name) { - if ($var_name[0] === '_') + if ($var_name[0] == '_') { + if (!$this->_exists($var_name)) + { + return false; + } + return memcache_get($this->memcache, $var_name); } else { - if (!sizeof($this->vars)) - { - $this->load(); - } - return (isset($this->vars[$var_name])) ? $this->vars[$var_name] : false; + return ($this->_exists($var_name)) ? $this->vars[$var_name] : false; } } /** * Put data into cache */ - public function put($var_name, $var, $ttl = 31536000) + function put($var_name, $var, $ttl = 2592000) { - if ($var_name[0] === '_') + if ($var_name[0] == '_') { memcache_set($this->memcache, $var_name, $var, 0, $ttl); } @@ -127,7 +135,7 @@ class acm /** * Purge cache data */ - public function purge() + function purge() { // Purge all phpbb cache files $dir = @opendir($this->cache_dir); @@ -144,7 +152,7 @@ class acm continue; } - @unlink($this->cache_dir . $entry); + $this->remove_file($this->cache_dir . $entry); } closedir($dir); @@ -152,20 +160,22 @@ class acm unset($this->vars); unset($this->sql_rowset); + unset($this->sql_row_pointer); $this->vars = array(); - $this->var_expires = array(); $this->sql_rowset = array(); + $this->sql_row_pointer = array(); $this->is_modified = false; } + /** * Destroy cache data */ - public function destroy($var_name, $table = '') + function destroy($var_name, $table = '') { - if ($var_name === 'sql' && !empty($table)) + if ($var_name == 'sql' && !empty($table)) { if (!is_array($table)) { @@ -176,6 +186,7 @@ class acm { // gives us the md5s that we want $temp = memcache_get($this->memcache, 'sql_' . $table_name); + if ($temp === false) { continue; @@ -194,7 +205,12 @@ class acm return; } - if ($var_name[0] === '_') + if (!$this->_exists($var_name)) + { + return; + } + + if ($var_name[0] == '_') { memcache_delete($this->memcache, $var_name); } @@ -208,10 +224,30 @@ class acm } } + /** + * Check if a given cache entry exist + */ + function _exists($var_name) + { + if ($var_name[0] == '_') + { + return true; + } + else + { + if (!sizeof($this->vars)) + { + $this->load(); + } + + return isset($this->vars[$var_name]); + } + } + /** * Load cached sql query */ - public function sql_load($query) + function sql_load($query) { // Remove extra spaces and tabs $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); @@ -225,7 +261,7 @@ class acm } $this->sql_rowset[$query_id] = $temp; - + $this->sql_row_pointer[$query_id] = 0; return $query_id; } @@ -233,25 +269,15 @@ class acm /** * Save sql query */ - public function sql_save($query, &$query_result, $ttl) + function sql_save($query, &$query_result, $ttl) { - global $db; - // Remove extra spaces and tabs $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); - // determine which tables this query belongs to: - - // grab all the FROM tables, avoid getting a LEFT JOIN - preg_match('/FROM \(?(\w+(?: (?!LEFT JOIN)\w+)?(?:, ?\w+(?: (?!LEFT JOIN)\w+)?)*)\)?/', $query, $regs); + // determine which tables this query belongs to + preg_match('/FROM \\(?(\\w+(?: \\w+)?(?:, ?\\w+(?: \\w+)?)*)\\)?/', $query, $regs); $tables = array_map('trim', explode(',', $regs[1])); - // now get the LEFT JOIN - preg_match_all('/LEFT JOIN\s+(\w+)(?: \w+)?/', $query, $result, PREG_PATTERN_ORDER); - $tables = array_merge($tables, $result[1]); - - $query_hash = md5($query); - foreach ($tables as $table_name) { if (($pos = strpos($table_name, ' ')) !== false) @@ -264,13 +290,14 @@ class acm { $temp = array(); } - $temp[$query_hash] = true; + $temp[md5($query)] = true; memcache_set($this->memcache, 'sql_' . $table_name, $temp, 0, $ttl); } // store them in the right place $query_id = sizeof($this->sql_rowset); $this->sql_rowset[$query_id] = array(); + $this->sql_row_pointer[$query_id] = 0; while ($row = $db->sql_fetchrow($query_result)) { @@ -278,35 +305,63 @@ class acm } $db->sql_freeresult($query_result); - memcache_set($this->memcache, 'sql_' . $query_hash, $this->sql_rowset[$query_id], 0, $ttl); + memcache_set($this->memcache, 'sql_' . md5($query), $this->sql_rowset[$query_id], 0, $ttl); $query_result = $query_id; } + /** + * Ceck if a given sql query exist in cache + */ + function sql_exists($query_id) + { + return isset($this->sql_rowset[$query_id]); + } + /** * Fetch row from cache (database) */ - public function sql_fetchrow($query_id) + function sql_fetchrow($query_id) { - list(, $row) = each($this->sql_rowset[$query_id]); + if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id])) + { + return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++]; + } - return ($row !== NULL) ? $row : false; + return false; } /** * Fetch a field from the current row of a cached database result (database) */ - public function sql_fetchfield($query_id, $field) + function sql_fetchfield($query_id, $field) { - $row = current($this->sql_rowset[$query_id]); + if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id])) + { + return (isset($this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field])) ? $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field] : false; + } - return ($row !== false && isset($row[$field])) ? $row[$field] : false; + return false; + } + + /** + * Seek a specific row in an a cached database result (database) + */ + function sql_rowseek($rownum, $query_id) + { + if ($rownum >= sizeof($this->sql_rowset[$query_id])) + { + return false; + } + + $this->sql_row_pointer[$query_id] = $rownum; + return true; } /** * Free memory used for a cached database result (database) */ - public function sql_freeresult($query_id) + function sql_freeresult($query_id) { if (!isset($this->sql_rowset[$query_id])) { @@ -314,9 +369,24 @@ class acm } unset($this->sql_rowset[$query_id]); + unset($this->sql_row_pointer[$query_id]); return true; } + + /** + * Removes/unlinks file + */ + function remove_file($filename, $check = false) + { + if ($check && !@is_writable($this->cache_dir)) + { + // E_USER_ERROR - not using language entry - intended. + trigger_error('Unable to remove files within ' . $this->cache_dir . '. Please check directory permissions.', E_USER_ERROR); + } + + return @unlink($filename); + } } ?> \ No newline at end of file -- cgit v1.2.1 From 84f795e9fbd172924280593d575bf4587c9b40e5 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 22 Feb 2009 18:06:05 +0000 Subject: $db-> to phpbb::$db-> git-svn-id: file:///svn/phpbb/trunk@9336 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/acm/acm_memcache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/acm/acm_memcache.php') diff --git a/phpBB/includes/acm/acm_memcache.php b/phpBB/includes/acm/acm_memcache.php index a89657b04e..175d0663a0 100644 --- a/phpBB/includes/acm/acm_memcache.php +++ b/phpBB/includes/acm/acm_memcache.php @@ -299,11 +299,11 @@ class acm $this->sql_rowset[$query_id] = array(); $this->sql_row_pointer[$query_id] = 0; - while ($row = $db->sql_fetchrow($query_result)) + while ($row = phpbb::$db->sql_fetchrow($query_result)) { $this->sql_rowset[$query_id][] = $row; } - $db->sql_freeresult($query_result); + phpbb::$db->sql_freeresult($query_result); memcache_set($this->memcache, 'sql_' . md5($query), $this->sql_rowset[$query_id], 0, $ttl); -- cgit v1.2.1 From bf8ac19eaa8d74f9dfd6d597190f5664e7339382 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 4 Oct 2009 18:13:59 +0000 Subject: Move trunk/phpBB to old_trunk/phpBB git-svn-id: file:///svn/phpbb/trunk@10210 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/acm/acm_memcache.php | 392 ------------------------------------ 1 file changed, 392 deletions(-) delete mode 100644 phpBB/includes/acm/acm_memcache.php (limited to 'phpBB/includes/acm/acm_memcache.php') diff --git a/phpBB/includes/acm/acm_memcache.php b/phpBB/includes/acm/acm_memcache.php deleted file mode 100644 index 175d0663a0..0000000000 --- a/phpBB/includes/acm/acm_memcache.php +++ /dev/null @@ -1,392 +0,0 @@ -cache_dir = $phpbb_root_path . 'cache/'; - $this->memcache = memcache_connect('localhost', 11211); - } - - /** - * Load global cache - */ - function load() - { - // grab the global cache - $this->vars = memcache_get($this->memcache, 'global'); - - if ($this->vars !== false) - { - return true; - } - - return false; - } - - /** - * Unload cache object - */ - function unload() - { - $this->save(); - unset($this->vars); - unset($this->sql_rowset); - unset($this->sql_row_pointer); - - $this->vars = array(); - $this->sql_rowset = array(); - $this->sql_row_pointer = array(); - } - - /** - * Save modified objects - */ - function save() - { - if (!$this->is_modified) - { - return; - } - - memcache_set($this->memcache, 'global', $this->vars, 0, 2592000); - - $this->is_modified = false; - } - - /** - * Tidy cache - */ - function tidy() - { - // cache has auto GC, no need to have any code here :) - - set_config('cache_last_gc', time(), true); - } - - /** - * Get saved cache object - */ - function get($var_name) - { - if ($var_name[0] == '_') - { - if (!$this->_exists($var_name)) - { - return false; - } - - return memcache_get($this->memcache, $var_name); - } - else - { - return ($this->_exists($var_name)) ? $this->vars[$var_name] : false; - } - } - - /** - * Put data into cache - */ - function put($var_name, $var, $ttl = 2592000) - { - if ($var_name[0] == '_') - { - memcache_set($this->memcache, $var_name, $var, 0, $ttl); - } - else - { - $this->vars[$var_name] = $var; - $this->is_modified = true; - } - } - - /** - * Purge cache data - */ - function purge() - { - // Purge all phpbb cache files - $dir = @opendir($this->cache_dir); - - if (!$dir) - { - return; - } - - while (($entry = readdir($dir)) !== false) - { - if (strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && strpos($entry, 'tpl_') !== 0) - { - continue; - } - - $this->remove_file($this->cache_dir . $entry); - } - closedir($dir); - - memcache_flush($this->memcache); - - unset($this->vars); - unset($this->sql_rowset); - unset($this->sql_row_pointer); - - $this->vars = array(); - $this->sql_rowset = array(); - $this->sql_row_pointer = array(); - - $this->is_modified = false; - } - - - /** - * Destroy cache data - */ - function destroy($var_name, $table = '') - { - if ($var_name == 'sql' && !empty($table)) - { - if (!is_array($table)) - { - $table = array($table); - } - - foreach ($table as $table_name) - { - // gives us the md5s that we want - $temp = memcache_get($this->memcache, 'sql_' . $table_name); - - if ($temp === false) - { - continue; - } - - // delete each query ref - foreach ($temp as $md5_id => $void) - { - memcache_delete($this->memcache, 'sql_' . $md5_id); - } - - // delete the table ref - memcache_delete($this->memcache, 'sql_' . $table_name); - } - - return; - } - - if (!$this->_exists($var_name)) - { - return; - } - - if ($var_name[0] == '_') - { - memcache_delete($this->memcache, $var_name); - } - else if (isset($this->vars[$var_name])) - { - $this->is_modified = true; - unset($this->vars[$var_name]); - - // We save here to let the following cache hits succeed - $this->save(); - } - } - - /** - * Check if a given cache entry exist - */ - function _exists($var_name) - { - if ($var_name[0] == '_') - { - return true; - } - else - { - if (!sizeof($this->vars)) - { - $this->load(); - } - - return isset($this->vars[$var_name]); - } - } - - /** - * Load cached sql query - */ - function sql_load($query) - { - // Remove extra spaces and tabs - $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); - $query_id = sizeof($this->sql_rowset); - - $temp = memcache_get($this->memcache, 'sql_' . md5($query)); - - if ($temp === false) - { - return false; - } - - $this->sql_rowset[$query_id] = $temp; - $this->sql_row_pointer[$query_id] = 0; - - return $query_id; - } - - /** - * Save sql query - */ - function sql_save($query, &$query_result, $ttl) - { - // Remove extra spaces and tabs - $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); - - // determine which tables this query belongs to - preg_match('/FROM \\(?(\\w+(?: \\w+)?(?:, ?\\w+(?: \\w+)?)*)\\)?/', $query, $regs); - $tables = array_map('trim', explode(',', $regs[1])); - - foreach ($tables as $table_name) - { - if (($pos = strpos($table_name, ' ')) !== false) - { - $table_name = substr($table_name, 0, $pos); - } - - $temp = memcache_get($this->memcache, 'sql_' . $table_name); - if ($temp === false) - { - $temp = array(); - } - $temp[md5($query)] = true; - memcache_set($this->memcache, 'sql_' . $table_name, $temp, 0, $ttl); - } - - // store them in the right place - $query_id = sizeof($this->sql_rowset); - $this->sql_rowset[$query_id] = array(); - $this->sql_row_pointer[$query_id] = 0; - - while ($row = phpbb::$db->sql_fetchrow($query_result)) - { - $this->sql_rowset[$query_id][] = $row; - } - phpbb::$db->sql_freeresult($query_result); - - memcache_set($this->memcache, 'sql_' . md5($query), $this->sql_rowset[$query_id], 0, $ttl); - - $query_result = $query_id; - } - - /** - * Ceck if a given sql query exist in cache - */ - function sql_exists($query_id) - { - return isset($this->sql_rowset[$query_id]); - } - - /** - * Fetch row from cache (database) - */ - function sql_fetchrow($query_id) - { - if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id])) - { - return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++]; - } - - return false; - } - - /** - * Fetch a field from the current row of a cached database result (database) - */ - function sql_fetchfield($query_id, $field) - { - if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id])) - { - return (isset($this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field])) ? $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field] : false; - } - - return false; - } - - /** - * Seek a specific row in an a cached database result (database) - */ - function sql_rowseek($rownum, $query_id) - { - if ($rownum >= sizeof($this->sql_rowset[$query_id])) - { - return false; - } - - $this->sql_row_pointer[$query_id] = $rownum; - return true; - } - - /** - * Free memory used for a cached database result (database) - */ - function sql_freeresult($query_id) - { - if (!isset($this->sql_rowset[$query_id])) - { - return false; - } - - unset($this->sql_rowset[$query_id]); - unset($this->sql_row_pointer[$query_id]); - - return true; - } - - /** - * Removes/unlinks file - */ - function remove_file($filename, $check = false) - { - if ($check && !@is_writable($this->cache_dir)) - { - // E_USER_ERROR - not using language entry - intended. - trigger_error('Unable to remove files within ' . $this->cache_dir . '. Please check directory permissions.', E_USER_ERROR); - } - - return @unlink($filename); - } -} - -?> \ No newline at end of file -- cgit v1.2.1 From 2e17e448deed073f8614bb555a8ef20c57291c2a Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 4 Oct 2009 18:14:59 +0000 Subject: Copy 3.0.x branch to trunk git-svn-id: file:///svn/phpbb/trunk@10211 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/acm/acm_memcache.php | 124 ++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 phpBB/includes/acm/acm_memcache.php (limited to 'phpBB/includes/acm/acm_memcache.php') diff --git a/phpBB/includes/acm/acm_memcache.php b/phpBB/includes/acm/acm_memcache.php new file mode 100644 index 0000000000..3077ee9615 --- /dev/null +++ b/phpBB/includes/acm/acm_memcache.php @@ -0,0 +1,124 @@ +memcache = new Memcache; + $this->memcache->connect(PHPBB_ACM_MEMCACHE_HOST, PHPBB_ACM_MEMCACHE_PORT); + $this->flags = (PHPBB_ACM_MEMCACHE_COMPRESS) ? MEMCACHE_COMPRESSED : 0; + } + + /** + * Unload the cache resources + * + * @return void + */ + function unload() + { + parent::unload(); + + $this->memcache->close(); + } + + /** + * Purge cache data + * + * @return void + */ + function purge() + { + $this->memcache->flush(); + + parent::purge(); + } + + /** + * Fetch an item from the cache + * + * @access protected + * @param string $var Cache key + * @return mixed Cached data + */ + function _read($var) + { + return $this->memcache->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->memcache->set($this->key_prefix . $var, $data, $this->flags, $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 $this->memcache->delete($this->key_prefix . $var); + } +} + +?> \ No newline at end of file -- cgit v1.2.1 From b68de2323d6444b4b3685a98bbcb9500a38e45cb Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Wed, 16 Dec 2009 15:48:23 +0000 Subject: merge changes from 3.0.x branch git-svn-id: file:///svn/phpbb/trunk@10342 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/acm/acm_memcache.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/acm/acm_memcache.php') diff --git a/phpBB/includes/acm/acm_memcache.php b/phpBB/includes/acm/acm_memcache.php index 3077ee9615..52b8832749 100644 --- a/phpBB/includes/acm/acm_memcache.php +++ b/phpBB/includes/acm/acm_memcache.php @@ -105,7 +105,11 @@ class acm extends acm_memory */ function _write($var, $data, $ttl = 2592000) { - return $this->memcache->set($this->key_prefix . $var, $data, $this->flags, $ttl); + if (!$this->memcache->replace($this->key_prefix . $var, $data, $this->flags, $ttl)) + { + return $this->memcache->set($this->key_prefix . $var, $data, $this->flags, $ttl); + } + return true; } /** -- cgit v1.2.1 From af5b9a96409d788733fcb1ff367e0c7fb0583702 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Tue, 9 Nov 2010 08:59:25 +0100 Subject: [ticket/9556] Drop php closing tags, add trailing newline Closing tags converted using Oleg's script. remove-php-end-tags.py -a . Trailing newlines added using the following where $ext is file extension. find . -type f -name "*.$ext" -print | xargs printf "e %s\nw\n" | ed -s; Extensions: php, css, html, js, xml. PHPBB3-9556 --- phpBB/includes/acm/acm_memcache.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'phpBB/includes/acm/acm_memcache.php') diff --git a/phpBB/includes/acm/acm_memcache.php b/phpBB/includes/acm/acm_memcache.php index e54fa36c38..527db71f80 100644 --- a/phpBB/includes/acm/acm_memcache.php +++ b/phpBB/includes/acm/acm_memcache.php @@ -134,5 +134,3 @@ class acm extends acm_memory return $this->memcache->delete($this->key_prefix . $var); } } - -?> -- cgit v1.2.1 From 9329b16ab13f3a4caf107df358c3c58bda2dcd8a Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 3 Nov 2010 18:35:31 +0100 Subject: [task/acm-refactor] Refactor the ACM classes to have a common interface. They are now refered to as cache drivers rather than ACM classes. The additional utility functions from the original cache class have been moved to the cache_service. The class loader is now instantiated without a cache instance and passed one as soon as it is constructed to allow autoloading the cache classes. PHPBB3-9983 --- phpBB/includes/acm/acm_memcache.php | 136 ------------------------------------ 1 file changed, 136 deletions(-) delete mode 100644 phpBB/includes/acm/acm_memcache.php (limited to 'phpBB/includes/acm/acm_memcache.php') diff --git a/phpBB/includes/acm/acm_memcache.php b/phpBB/includes/acm/acm_memcache.php deleted file mode 100644 index 527db71f80..0000000000 --- a/phpBB/includes/acm/acm_memcache.php +++ /dev/null @@ -1,136 +0,0 @@ -memcache = new Memcache; - foreach(explode(',', PHPBB_ACM_MEMCACHE) as $u) - { - $parts = explode('/', $u); - $this->memcache->addServer(trim($parts[0]), trim($parts[1])); - } - $this->flags = (PHPBB_ACM_MEMCACHE_COMPRESS) ? MEMCACHE_COMPRESSED : 0; - } - - /** - * Unload the cache resources - * - * @return void - */ - function unload() - { - parent::unload(); - - $this->memcache->close(); - } - - /** - * Purge cache data - * - * @return void - */ - function purge() - { - $this->memcache->flush(); - - parent::purge(); - } - - /** - * Fetch an item from the cache - * - * @access protected - * @param string $var Cache key - * @return mixed Cached data - */ - function _read($var) - { - return $this->memcache->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) - { - if (!$this->memcache->replace($this->key_prefix . $var, $data, $this->flags, $ttl)) - { - return $this->memcache->set($this->key_prefix . $var, $data, $this->flags, $ttl); - } - return true; - } - - /** - * Remove an item from the cache - * - * @access protected - * @param string $var Cache key - * @return bool True if the operation succeeded - */ - function _delete($var) - { - return $this->memcache->delete($this->key_prefix . $var); - } -} -- cgit v1.2.1