Monday, May 8th, 2006Monday, May 8th, 2006

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);
	}
}

UpdateI just found out APC datastore support was added to the yet unreleased vBulletin 3.6. Nice!

Update 2I've since switched back to eAccelerator. APC was causing Apache segfaults under ultra-high loads.

10 Responses to “APC Datastore Class For vBulletin”

  1. BamaStangGuy Says:

    That is a shame. Hopefully they will fix this soon

  2. Tim Says:

    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.

  3. Shawn Says:

    Currently running 0.9.5 beta 2 without any problems.

  4. Tim Says:

    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).

  5. arigoner Says:

    One old american man win in lotto 250 000 000$.
    I want win money too!!!!!!!!!!a-a-a-a
    Give me money!

  6. Bob Van Zant Says:

    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.

  7. Gestores de contenido que aprovechan los aceleradores PHP Says:

    […] Si todavía usan vB 3.6.X hay un plugin para activarlo con XCache y otro más para APC (probablemente deberían actualizar vB ). Un plugin muy recomendado es este otro que guarda en el datastores toda las plantillas de los estilos (style templates) de vBulletin. […]

  8. Gestores de contenido que aprovechan los aceleradores PHP | Andrebills Says:

    […] Si todavía usan vB 3.6.X hay un plugin para activarlo con XCache y otro más para APC (probablemente deberían actualizar vB ). Un plugin muy recomendado es este otro que guarda en el datastores toda las plantillas de los estilos (style templates) de vBulletin. […]

  9. Para los Copy Paste » Blog Archive » Gestores de contenido que aprovechan los aceleradores PHP Says:

    […] Si todavía usan vB 3.6.X hay un plugin para activarlo con XCache y otro más para APC (probablemente deberían actualizar vB ). Un plugin muy recomendado es este otro que guarda en el datastores toda las plantillas de los estilos (style templates) de vBulletin. […]

  10. Blog de PHP - FinderIT » Blog Archive » Gestores de contenido que aprovechan los aceleradores PHP Says:

    […] Si todavía usan vB 3.6.X hay un plugin para activarlo con XCache y otro más para APC (probablemente deberían actualizar vB ). Un plugin muy recomendado es este otro que guarda en el datastores toda las plantillas de los estilos (style templates) de vBulletin. […]

Leave a Reply