PDA

View Full Version : Board Optimization - Datastore cache to WinCache - boost your vBulletin


hydn
03-21-2010, 10:00 PM
Also see: Wincache for vb 4.0.2 (https://vborg.vbsupport.ru/showthread.php?p=2012671)

This allows you to use WinCache (http://www.iis.net/expand/WinCacheForPhp) as a datastore cache in vBulletin. This also assumes that you have already installed Wincache version 1.1 or later. This is definitely your choice if you have already installed and enabled WinCache on your IIS server. Use at your own risk!

(See screenshot of stats below after 30mins up-time)


Prerequisites
a working php installation

a working vBulletin 3.8.x installation

a working WinCache 1.1 or Better.Install the modification
Add the following code to the end of class_datastore.php just above "?>"
// ################################################## ###########################
// WINCACHE

/**
* Class for fetching and initializing the vBulletin datastore from WINCACHE
*/

class vB_Datastore_WINCACHE extends vB_Datastore
{
/**
* Indicates if the result of a call to the register function should store the value in memory
*
* @var boolean
*/

var $store_result = false;

/**
* Fetches the contents of the datastore from WINCACHE
*
* @param array Array of items to fetch from the datastore
*
* @return void
*/
function fetch($itemarray)
{
if (!function_exists('wincache_ucache_get'))
{
trigger_error('WINCACHE not installed', E_USER_ERROR);
}

$db =& $this->dbobject;

$itemlist = array();

foreach ($this->defaultitems AS $item)
{
$this->do_fetch($item, $itemlist);
}

if (is_array($itemarray))
{
foreach ($itemarray AS $item)
{
$this->do_fetch($item, $itemlist);
}
}

$this->store_result = true;

// some of the items we are looking for were not found, lets get them in one go
if (!empty($itemlist))
{
$this->do_db_fetch(implode(',', $itemlist));
}

$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
* @param array A reference to an array of items that failed and need to fetched from the database
*
* @return boolean
*/
function do_fetch($title, &$itemlist)
{
$ptitle = $this->prefix . $title;

if (($data = wincache_ucache_get($ptitle)) === false)
{ // appears its not there, lets grab the data, lock the shared memory and put it in
$itemlist[] = "'" . $this->dbobject->escape_string($title) . "'";
return false;
}
$this->register($title, $data);
return true;
}

/**
* Sorts the data returned from the cache and places it into appropriate places
*
* @param string The name of the data item to be processed
* @param mixed The data associated with the title
*
* @return void
*/
function register($title, $data, $unserialize_detect = 2)
{
if ($this->store_result === true)
{
$this->build($title, $data);
}
parent::register($title, $data, $unserialize_detect);
}

/**
* Updates the appropriate cache file
*
* @param string title of the datastore item
* @param mixed The data associated with the title
*
* @return void
*/
function build($title, $data)
{
$ptitle = $this->prefix . $title;
//The below line is not required as wincache_ucache_set will override the data if it is already present
//wincache_ucache_delete($ptitle);
wincache_ucache_set($ptitle, $data);
}
}
2. Set your config.php to use wincache for datastore:

$config['Datastore']['class'] = 'vB_Datastore_WINCACHE';Done!

Check the "User and Session Cache" section of your wincache.php (screenshot) in your browser to see stats!

Special thanks to the guys at Microsoft for their help! Official IIS support at http://forums.iis.net

Enjoy!

hydn
03-22-2010, 01:26 AM
Reserved.

puertoblack2003
03-22-2010, 10:02 AM
this also works with Apache on windows :)

hydn
03-22-2010, 01:45 PM
Yes it should. I have not tested and thus don't like to tell others to install something without knowing that it works :)

Daryn
03-22-2010, 06:38 PM
Got this installed and it seems to be working. I don't think I've seen vB this fast before.

Just a note though, your code for class_datastore has the closing ?> at the end of it, that would end up being a double close if you pasted it as is.

AzzidReign
03-23-2010, 02:06 PM
This is great! Thx.

hollyboy
03-27-2010, 10:12 AM
is there a similar mod for linux server?

hydn
03-28-2010, 03:16 AM
is there a similar mod for linux server?
wincache is for windows servers only.

final kaoss
03-28-2010, 03:21 AM
LinCache would be good.

ps2wiz
03-28-2010, 11:15 PM
Will this work in VB4?

hydn
03-28-2010, 11:27 PM
Will this work in VB4?

no sorry

ps2wiz
04-05-2010, 07:32 PM
no sorry

How about 3.7?

Hostboard
04-06-2010, 01:09 PM
Why do you recommend V1.1 or higher when it is a beta release. Shouldn't 1.0 work as well since that was the last stable release?

hydn
04-06-2010, 10:31 PM
Why do you recommend V1.1 or higher when it is a beta release. Shouldn't 1.0 work as well since that was the last stable release?
Use version 1.0 and let me know how that works out for you. :)

ps2wiz
04-07-2010, 01:34 AM
How about 3.7?

Will this mod work in a 3.7 board?

Why do you recommend V1.1 or higher when it is a beta release. Shouldn't 1.0 work as well since that was the last stable release?

Windows Cache Extension 1.1 for PHP is an incremental release that includes all the features from version 1.0 and adds support for user and session cache. The extension provides API's that can be used by PHP applications to store variables in shared memory. In addition the extension includes the PHP session handler that can be used by PHP engine to store session data in shared memory instead of file system.

hydn
04-07-2010, 02:48 AM
I never tested 3.7. Don't know if it works.

Upgrade the speed is worth it

hydn
04-10-2010, 04:43 PM
This is great! Thx.

y welcome

MichaelDance
04-26-2010, 07:20 AM
Thanks im using this all installed, hope it improves the board.

ps2wiz
05-01-2010, 08:15 PM
I never tested 3.7. Don't know if it works.


I just tried it out, and I can confirm that it does not work with my 3.7 board.

|Jordan|
07-12-2010, 05:43 AM
I installed this mod and I dont see "User and Session Cache" tab on my wincache.php and i have the latest Wincache installed.

P.S. I found out i had to manually enable the user cache, but doing so still doesnt display the user cache tab.

Absolution
07-06-2011, 06:19 AM
Working on vbulletin 4.1.4 still.

Thanks for the mod, I never realized how good wincache is. I literally could handle over 2x as many users with it enabled.