APC Datastore Class For vBulletin
On one of my ultra-high traffic web servers, I switched from eAccelerator to APC today (an opcode/caching system for PHP). So far it seems pretty nice... Especially the ability to disable stat for each PHP request.
I ended up making a datastore class for vBulletin also so I could use it for the forum, so if anyone else is using vBulletin on a server with APC, here you go (if you know what this is for, you will know where it goes
).
// ############################################################################# // APC /** * Class for fetching and initializing the vBulletin datastore from APC * * @package vBulletin * @version $Revision: 0.0.0.1 $ * @date $Date: 2006/05/08 16:51:06 $ */ class vB_Datastore_APC extends vB_Datastore { /** * Fetches the contents of the datastore from APC * * @param array Array of items to fetch from the datastore * * @return void */ function fetch($itemarray) { if (!function_exists('apc_fetch')) { trigger_error('APC not installed', E_USER_ERROR); } foreach ($this->defaultitems AS $item) { $this->do_fetch($item); } if (is_array($itemarray)) { foreach ($itemarray AS $item) { $this->do_fetch($item); } } $this->check_options(); // set the version number variable $this->registry->versionnumber =& $this->registry->options['templateversion']; } /** * Fetches the data from shared memory and detects errors * * @param string title of the datastore item * * @return void */ function do_fetch($title) { $ptitle = $this->prefix . $title; if (($data = apc_fetch($ptitle)) === false) { // appears its not there, lets grab the data and put it in memory $data = ''; if ($dataitem = $this->dbobject->query_first(" SELECT title, data FROM " . TABLE_PREFIX . "datastore WHERE title = '" . $this->dbobject->escape_string($title) ."' ")) { $data =& $dataitem['data']; } $this->build($title, $data); } $this->register($title, $data); } /** * Updates the appropriate cache file * * @param string title of the datastore item * * @return void */ function build($title, $data) { $title = $this->prefix . $title; if (!function_exists('apc_store')) { trigger_error('APC not installed', E_USER_ERROR); } $check = apc_store($title, $data); } }
I'm a boy... from San Diego, CA (USA). And I don't really have a whole lot else to say about myself.