What the hell??!? (blah, blah of a wannabe alien)
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
).
[code=php]// #############################################################################
// 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);
}
}[/code]
| Print article | This entry was posted by Shawn on May 8, 2006 at 11:32 pm, and is filed under Coding, Server Admin. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 5 years ago
That is a shame. Hopefully they will fix this soon
about 5 years ago
Shawn – What version of eacclerator are you currently using? I’m on OS X Server and recently upgraded to 0.9.5 and I’m getting tons of Apache segfaults with that version. I’m about to revert to my last known good version which was 0.9.3.
about 5 years ago
Currently running 0.9.5 beta 2 without any problems.
about 5 years ago
Thanks Shawn, I appreciate the report. I reverted back to 0.9.3 and so far no more issues. When I had 0.9.5 running it would bring one of my Xserves to its knees a couple of times per day (to the point of watchdog not being able to hear from the PMU and forcing a reboot).
about 5 years ago
One old american man win in lotto 250 000 000$.
I want win money too!!!!!!!!!!a-a-a-a
Give me money!
about 4 years ago
I had problems with APC a while ago but after digging through stack traces and filing bugs the kind folks over there at APC fixed this for me. One of the bugs I was encountering had to do with expiring entries from the cache. By setting my cache large enough (100MB, vBulletin, surprisingly, doesn’t have that much crap to cache) I avoided that final bug. I’m using APC v3.0.12p2 and haven’t segfaulted in months.