Difference between revisions of "User:TerryE/phpBB3.0.4 Migration/Cache Tuning"

From Apache OpenOffice Wiki
Jump to: navigation, search
(New page: = A PHP Cache (APC) Tuning = Any time phpBB executes a SQL query, style template, or dataset retrieval, it creates an md5 of the sql query / tempate and stores this under the name sql_<md...)
 
(No difference)

Revision as of 07:13, 22 May 2009

A PHP Cache (APC) Tuning

Any time phpBB executes a SQL query, style template, or dataset retrieval, it creates an md5 of the sql query / tempate and stores this under the name sql_<md5Value> in the cache (or euqivalent for the other types). Before executing the query, it does an existence check for the file andexecutes an @include it to evaluate it. PHP loades the cached bytecode version instead. Here is a typical example

      <?php
       /* SELECT COUNT(DISTINCT s.session_ip) as num_guests FROM phpbb_en_sessions s \
          WHEREs.session_user_id = 1 AND s.session_time >= 1242322740 AND s.session_forum_id = 61   */
       $expired = (time() > 1242323134) ? true : false;
       if ($expired) { return; }
       $this->sql_rowset[$query_id] = unserialize('a:1:{i:0;a:1:{s:10:"num_guests";s:1:"0";}}');
       ?>
This code sets the boolean $expired and if false then also returns the results set. If true or the file doesn't exist then the execution does the SQL query then creates this file (but only for what the application deems as reusable queries). With this phpBB cache the results are latched for a specific time (in this example the expiry time was some 6 mins after the start of the session) even if the underlying DB data has changed. Thanks to the APC, the code for this is also cached to executing this is quick. This approach is different to the MySQL cache, where the execution plan for each SQL queries is cached in an LRU buffer. This saves parse costs, but the query is still re-evaluated each call.
Personal tools