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_xcache.php | 368 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 368 insertions(+) create mode 100644 phpBB/includes/acm/acm_xcache.php (limited to 'phpBB/includes/acm/acm_xcache.php') diff --git a/phpBB/includes/acm/acm_xcache.php b/phpBB/includes/acm/acm_xcache.php new file mode 100644 index 0000000000..cf1494a4c7 --- /dev/null +++ b/phpBB/includes/acm/acm_xcache.php @@ -0,0 +1,368 @@ +cache_dir = $phpbb_root_path . 'cache/'; + } + + /** + * Load global cache + */ + private function load() + { + global $phpEx; + + // grab the global cache + if (xcache_isset('global')) + { + $this->vars = xcache_get('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; + } + + xcache_set('global', $this->vars, 31536000); + + $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 (xcache_isset($var_name)) ? xcache_get($var_name) : false; + } + 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] === '_') + { + xcache_set($var_name, $var, $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); + + $n = xcache_count(XC_TYPE_VAR); + for ($i = 0; $i < $n; $i++) + { + xcache_clear_cache(XC_TYPE_VAR, $i); + } + + 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 + if (!xcache_isset('sql_' . $table_name)) + { + continue; + } + $temp = xcache_get('sql_' . $table_name); + + // delete each query ref + foreach ($temp as $md5_id => $void) + { + xcache_unset('sql_' . $md5_id); + } + + // delete the table ref + xcache_unset('sql_' . $table_name); + } + + return; + } + + if ($var_name[0] === '_') + { + xcache_unset($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); + + $query_hash = md5($query); + + if (!xcache_isset('sql_' . $query_hash)) + { + return false; + } + + $this->sql_rowset[$query_id] = xcache_get('sql_' . $query_hash); + + $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); + } + + if (xcache_isset('sql_' . $table_name)) + { + $temp = xcache_get('sql_' . $table_name); + } + else + { + $temp = array(); + } + $temp[$query_hash] = true; + xcache_set('sql_' . $table_name, $temp, $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); + + xcache_set('sql_' . $query_hash, $this->sql_rowset[$query_id], $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_xcache.php | 36 ++++-------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) (limited to 'phpBB/includes/acm/acm_xcache.php') diff --git a/phpBB/includes/acm/acm_xcache.php b/phpBB/includes/acm/acm_xcache.php index cf1494a4c7..542dc60abb 100644 --- a/phpBB/includes/acm/acm_xcache.php +++ b/phpBB/includes/acm/acm_xcache.php @@ -26,7 +26,6 @@ class acm private $is_modified = false; public $sql_rowset = array(); - private $sql_row_pointer = array(); public $cache_dir = ''; /** @@ -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(); } /** @@ -166,12 +163,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; } @@ -246,7 +241,6 @@ class acm $this->sql_rowset[$query_id] = xcache_get('sql_' . $query_hash); - $this->sql_row_pointer[$query_id] = 0; return $query_id; } @@ -295,7 +289,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)) { @@ -313,12 +306,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; } /** @@ -326,26 +316,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; } /** @@ -359,7 +332,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_xcache.php | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'phpBB/includes/acm/acm_xcache.php') diff --git a/phpBB/includes/acm/acm_xcache.php b/phpBB/includes/acm/acm_xcache.php index 542dc60abb..38db4d27d8 100644 --- a/phpBB/includes/acm/acm_xcache.php +++ b/phpBB/includes/acm/acm_xcache.php @@ -33,8 +33,7 @@ class acm */ function __construct() { - global $phpbb_root_path; - $this->cache_dir = $phpbb_root_path . 'cache/'; + $this->cache_dir = PHPBB_ROOT_PATH . 'cache/'; } /** @@ -42,8 +41,6 @@ class acm */ private function load() { - global $phpEx; - // grab the global cache if (xcache_isset('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 (xcache_isset($var_name)) ? xcache_get($var_name) : false; } else @@ -176,8 +169,6 @@ class acm */ public function destroy($var_name, $table = '') { - global $phpEx; - if ($var_name === 'sql' && !empty($table)) { if (!is_array($table)) @@ -226,8 +217,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); @@ -250,7 +239,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_xcache.php | 133 ++++++++++++++++++++------------------ 1 file changed, 70 insertions(+), 63 deletions(-) (limited to 'phpBB/includes/acm/acm_xcache.php') diff --git a/phpBB/includes/acm/acm_xcache.php b/phpBB/includes/acm/acm_xcache.php index 38db4d27d8..9531f5e03d 100644 --- a/phpBB/includes/acm/acm_xcache.php +++ b/phpBB/includes/acm/acm_xcache.php @@ -1,45 +1,38 @@ cache_dir = PHPBB_ROOT_PATH . 'cache/'; + $this->cache_dir = $phpbb_root_path . 'cache/'; } /** * Load global cache */ - private function load() + function load() { // grab the global cache if (xcache_isset('global')) @@ -54,20 +47,18 @@ class acm /** * Unload cache object */ - public function unload() + function unload() { $this->save(); unset($this->vars); unset($this->sql_rowset); - - $this->vars = array(); - $this->sql_rowset = array(); + unset($this->sql_row_pointer); } /** * Save modified objects */ - private function save() + function save() { if (!$this->is_modified) { @@ -82,7 +73,7 @@ class acm /** * Tidy cache */ - public function tidy() + function tidy() { // cache has auto GC, no need to have any code here :) @@ -92,9 +83,9 @@ class acm /** * Get saved cache object */ - public function get($var_name) + function get($var_name) { - if ($var_name[0] === '_') + if ($var_name[0] == '_') { return (xcache_isset($var_name)) ? xcache_get($var_name) : false; } @@ -111,9 +102,9 @@ class acm /** * Put data into cache */ - public function put($var_name, $var, $ttl = 31536000) + function put($var_name, $var, $ttl = 31536000) { - if ($var_name[0] === '_') + if ($var_name[0] == '_') { xcache_set($var_name, $var, $ttl); } @@ -127,7 +118,7 @@ class acm /** * Purge cache data */ - public function purge() + function purge() { // Purge all phpbb cache files $dir = @opendir($this->cache_dir); @@ -156,10 +147,7 @@ class acm unset($this->vars); unset($this->sql_rowset); - - $this->vars = array(); - $this->var_expires = array(); - $this->sql_rowset = array(); + unset($this->sql_row_pointer); $this->is_modified = false; } @@ -167,9 +155,9 @@ class acm /** * 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)) { @@ -198,7 +186,7 @@ class acm return; } - if ($var_name[0] === '_') + if ($var_name[0] == '_') { xcache_unset($var_name); } @@ -215,21 +203,20 @@ class acm /** * 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); $query_id = sizeof($this->sql_rowset); - $query_hash = md5($query); - - if (!xcache_isset('sql_' . $query_hash)) + if (!xcache_isset('sql_' . md5($query))) { return false; } - $this->sql_rowset[$query_id] = xcache_get('sql_' . $query_hash); + $this->sql_rowset[$query_id] = xcache_get('sql_' . md5($query)); + $this->sql_row_pointer[$query_id] = 0; return $query_id; } @@ -237,25 +224,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) @@ -271,13 +248,14 @@ class acm { $temp = array(); } - $temp[$query_hash] = true; + $temp[md5($query)] = true; xcache_set('sql_' . $table_name, $temp, $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)) { @@ -285,35 +263,63 @@ class acm } $db->sql_freeresult($query_result); - xcache_set('sql_' . $query_hash, $this->sql_rowset[$query_id], $ttl); + xcache_set('sql_' . md5($query), $this->sql_rowset[$query_id], $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 false; + } - return ($row !== false && isset($row[$field])) ? $row[$field] : 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])) { @@ -321,6 +327,7 @@ class acm } unset($this->sql_rowset[$query_id]); + unset($this->sql_row_pointer[$query_id]); return true; } -- 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_xcache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/acm/acm_xcache.php') diff --git a/phpBB/includes/acm/acm_xcache.php b/phpBB/includes/acm/acm_xcache.php index 9531f5e03d..e2bf21748a 100644 --- a/phpBB/includes/acm/acm_xcache.php +++ b/phpBB/includes/acm/acm_xcache.php @@ -257,11 +257,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); xcache_set('sql_' . md5($query), $this->sql_rowset[$query_id], $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_xcache.php | 336 -------------------------------------- 1 file changed, 336 deletions(-) delete mode 100644 phpBB/includes/acm/acm_xcache.php (limited to 'phpBB/includes/acm/acm_xcache.php') diff --git a/phpBB/includes/acm/acm_xcache.php b/phpBB/includes/acm/acm_xcache.php deleted file mode 100644 index e2bf21748a..0000000000 --- a/phpBB/includes/acm/acm_xcache.php +++ /dev/null @@ -1,336 +0,0 @@ -cache_dir = $phpbb_root_path . 'cache/'; - } - - /** - * Load global cache - */ - function load() - { - // grab the global cache - if (xcache_isset('global')) - { - $this->vars = xcache_get('global'); - return true; - } - - return false; - } - - /** - * Unload cache object - */ - function unload() - { - $this->save(); - unset($this->vars); - unset($this->sql_rowset); - unset($this->sql_row_pointer); - } - - /** - * Save modified objects - */ - function save() - { - if (!$this->is_modified) - { - return; - } - - xcache_set('global', $this->vars, 31536000); - - $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] == '_') - { - return (xcache_isset($var_name)) ? xcache_get($var_name) : false; - } - else - { - if (!sizeof($this->vars)) - { - $this->load(); - } - return (isset($this->vars[$var_name])) ? $this->vars[$var_name] : false; - } - } - - /** - * Put data into cache - */ - function put($var_name, $var, $ttl = 31536000) - { - if ($var_name[0] == '_') - { - xcache_set($var_name, $var, $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; - } - - @unlink($this->cache_dir . $entry); - } - closedir($dir); - - $n = xcache_count(XC_TYPE_VAR); - for ($i = 0; $i < $n; $i++) - { - xcache_clear_cache(XC_TYPE_VAR, $i); - } - - unset($this->vars); - unset($this->sql_rowset); - unset($this->sql_row_pointer); - - $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 - if (!xcache_isset('sql_' . $table_name)) - { - continue; - } - $temp = xcache_get('sql_' . $table_name); - - // delete each query ref - foreach ($temp as $md5_id => $void) - { - xcache_unset('sql_' . $md5_id); - } - - // delete the table ref - xcache_unset('sql_' . $table_name); - } - - return; - } - - if ($var_name[0] == '_') - { - xcache_unset($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 - */ - function sql_load($query) - { - // Remove extra spaces and tabs - $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); - $query_id = sizeof($this->sql_rowset); - - if (!xcache_isset('sql_' . md5($query))) - { - return false; - } - - $this->sql_rowset[$query_id] = xcache_get('sql_' . md5($query)); - - $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); - } - - if (xcache_isset('sql_' . $table_name)) - { - $temp = xcache_get('sql_' . $table_name); - } - else - { - $temp = array(); - } - $temp[md5($query)] = true; - xcache_set('sql_' . $table_name, $temp, $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); - - xcache_set('sql_' . md5($query), $this->sql_rowset[$query_id], $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; - } -} - -?> \ 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_xcache.php | 121 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 phpBB/includes/acm/acm_xcache.php (limited to 'phpBB/includes/acm/acm_xcache.php') diff --git a/phpBB/includes/acm/acm_xcache.php b/phpBB/includes/acm/acm_xcache.php new file mode 100644 index 0000000000..d0a614660c --- /dev/null +++ b/phpBB/includes/acm/acm_xcache.php @@ -0,0 +1,121 @@ + 0 +* - xcache.admin.enable_auth = off (or xcache.admin.user and xcache.admin.password set) +* +*/ +class acm extends acm_memory +{ + var $extension = 'XCache'; + + function acm() + { + parent::acm_memory(); + + if (!function_exists('ini_get') || (int) ini_get('xcache.var_size') <= 0) + { + trigger_error('Increase xcache.var_size setting above 0 or enable ini_get() to use this ACM module.', E_USER_ERROR); + } + } + + /** + * Purge cache data + * + * @return void + */ + function purge() + { + // Run before for XCache, if admin functions are disabled it will terminate execution + parent::purge(); + + // If the admin authentication is enabled but not set up, this will cause a nasty error. + // Not much we can do about it though. + $n = xcache_count(XC_TYPE_VAR); + + for ($i = 0; $i < $n; $i++) + { + xcache_clear_cache(XC_TYPE_VAR, $i); + } + } + + /** + * Fetch an item from the cache + * + * @access protected + * @param string $var Cache key + * @return mixed Cached data + */ + function _read($var) + { + $result = xcache_get($this->key_prefix . $var); + + return ($result !== null) ? $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 xcache_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 xcache_unset($this->key_prefix . $var); + } + + /** + * Check if a cache var exists + * + * @access protected + * @param string $var Cache key + * @return bool True if it exists, otherwise false + */ + function _isset($var) + { + return xcache_isset($this->key_prefix . $var); + } +} + +?> \ No newline at end of file -- 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_xcache.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'phpBB/includes/acm/acm_xcache.php') diff --git a/phpBB/includes/acm/acm_xcache.php b/phpBB/includes/acm/acm_xcache.php index d0a614660c..8be0ad0c48 100644 --- a/phpBB/includes/acm/acm_xcache.php +++ b/phpBB/includes/acm/acm_xcache.php @@ -117,5 +117,3 @@ class acm extends acm_memory return xcache_isset($this->key_prefix . $var); } } - -?> \ No newline at end of file -- 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_xcache.php | 119 -------------------------------------- 1 file changed, 119 deletions(-) delete mode 100644 phpBB/includes/acm/acm_xcache.php (limited to 'phpBB/includes/acm/acm_xcache.php') diff --git a/phpBB/includes/acm/acm_xcache.php b/phpBB/includes/acm/acm_xcache.php deleted file mode 100644 index 8be0ad0c48..0000000000 --- a/phpBB/includes/acm/acm_xcache.php +++ /dev/null @@ -1,119 +0,0 @@ - 0 -* - xcache.admin.enable_auth = off (or xcache.admin.user and xcache.admin.password set) -* -*/ -class acm extends acm_memory -{ - var $extension = 'XCache'; - - function acm() - { - parent::acm_memory(); - - if (!function_exists('ini_get') || (int) ini_get('xcache.var_size') <= 0) - { - trigger_error('Increase xcache.var_size setting above 0 or enable ini_get() to use this ACM module.', E_USER_ERROR); - } - } - - /** - * Purge cache data - * - * @return void - */ - function purge() - { - // Run before for XCache, if admin functions are disabled it will terminate execution - parent::purge(); - - // If the admin authentication is enabled but not set up, this will cause a nasty error. - // Not much we can do about it though. - $n = xcache_count(XC_TYPE_VAR); - - for ($i = 0; $i < $n; $i++) - { - xcache_clear_cache(XC_TYPE_VAR, $i); - } - } - - /** - * Fetch an item from the cache - * - * @access protected - * @param string $var Cache key - * @return mixed Cached data - */ - function _read($var) - { - $result = xcache_get($this->key_prefix . $var); - - return ($result !== null) ? $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 xcache_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 xcache_unset($this->key_prefix . $var); - } - - /** - * Check if a cache var exists - * - * @access protected - * @param string $var Cache key - * @return bool True if it exists, otherwise false - */ - function _isset($var) - { - return xcache_isset($this->key_prefix . $var); - } -} -- cgit v1.2.1