This post isn't a guide to installing memcached. It's not a difficult process, and there already plenty of resources out there that will teach you how to do that. I also assume that there are two types of people reading this-- those with managed hosting and those who manage their own servers. If you're one of the latter, you should be able to figure it out. If you're one of the former, call your hosting company and tell them you want memcached installed and configured to run with php. They'll know what you're talking about. If they don't, you should probably switch hosts.
Also, this is primarily for UNIX servers, however there is a port of memcached for Windows. I just haven't used it before, so proceed at your own risk.
Getting Started
The first thing you'll need to do is make sure that memcached is running. If you have shell access, type the following:
Code:
$ ps ax|grep memcached
9101 pts/0 S+ 0:00 grep memcached
17541 ? Ssl 15:07 memcached -d -p 11211 -u nobody -c 1024 -m 64
17541 ? Ssl 15:07 memcached -d -p 11211 -u nobody -c 1024 -m 64
Create a file called memcached-test.php on your server that has the following contents:
PHP Code:
<?
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");
echo "Server's version: {$memcache->getVersion()}
";
$tmp = new stdClass;
$tmp->string_attribute = 'testing';
$tmp->string_attribute = 123;
$memcache->set('key', $tmp, false, 10) or die ("Failed to save temporary object at memcache server");
echo "Data from the cache:
\n";
print_r($memcache->get('key'));
?>
Server's version: 1.2.6
Data from the cache:
stdClass Object ( [string_attribute] => 123 )
Data from the cache:
stdClass Object ( [string_attribute] => 123 )
Enabling Memcached
You're now ready to edit your config.php file. Please, back up this file before you start editing it. Around line 135 (in a brand new 3.7.4 config.php file at least) you will see a commented out section entitled "DATASTORE CACHE CONFIGURATION". This is where we're going to configure memcached. Find the section that looks like this:
PHP Code:
/*
$config['Datastore']['class'] = 'vB_Datastore_Memcached';
$i = 0;
// First Server
$i++;
$config['Misc']['memcacheserver'][$i] = '127.0.0.1';
$config['Misc']['memcacheport'][$i] = 11211;
$config['Misc']['memcachepersistent'][$i] = true;
$config['Misc']['memcacheweight'][$i] = 1;
$config['Misc']['memcachetimeout'][$i] = 1;
$config['Misc']['memcacheretry_interval'][$i] = 15;
*/
To set up memcached to use pooling, you first need to know the IP's of each server. Your host should be able to provide you with this information. You can also use host names, but let's just keep this simple for now. Then, you want to copy the memcached settings from "// First Server" to the closing comment so that it looks like this:
PHP Code:
$config['Datastore']['class'] = 'vB_Datastore_Memcached';
$i = 0;
// First Server
$i++;
$config['Misc']['memcacheserver'][$i] = '111.111.11.111'; // ip of the first server
$config['Misc']['memcacheport'][$i] = 11211;
$config['Misc']['memcachepersistent'][$i] = true;
$config['Misc']['memcacheweight'][$i] = 1;
$config['Misc']['memcachetimeout'][$i] = 1;
$config['Misc']['memcacheretry_interval'][$i] = 15;
// Second Server
$i++;
$config['Misc']['memcacheserver'][$i] = '111.111.11.222'; // ip of the second server
$config['Misc']['memcacheport'][$i] = 11211;
$config['Misc']['memcachepersistent'][$i] = true;
$config['Misc']['memcacheweight'][$i] = 1;
$config['Misc']['memcachetimeout'][$i] = 1;
$config['Misc']['memcacheretry_interval'][$i] = 15;
// Third Server
$i++;
$config['Misc']['memcacheserver'][$i] = '111.111.11.333'; // ip of the third server
$config['Misc']['memcacheport'][$i] = 11211;
$config['Misc']['memcachepersistent'][$i] = true;
$config['Misc']['memcacheweight'][$i] = 1;
$config['Misc']['memcachetimeout'][$i] = 1;
$config['Misc']['memcacheretry_interval'][$i] = 15;
After you save your config file, you should immediately go to your forum to make sure that it's still up. If something is configured wrong, you'll see a white page with an error at the top. If the forum is still up, you're in good shape. Just to be sure, I usually log into the shell, run 'top', and look for memcached to show up on the list. This just tells me that it's doing something. If your forum runs vBSEO, you should log into the control panel and enable memcached under the 'Caching Options'. Please note that vBSEO requires a more recent version of memcached than vB does.
Note: After reading through this post, it really sounds like this is a difficult process. It honestly isn't. I considered making a dumbed down "John Wayne's Guide to Configuring Memcached", but decided against it. For anyone who is gutsy, you can probably figure out what I'm talking about and try it that way, although I wouldn't recommend it.
I've doubled checked everything and there's nothing I've missed to the best of my knowledge. I've exactly the same settings except the memached server being the 127.0.0.1.
After enabling it, my registration page shows database error. Upon trying to visit optimize/repair page through admincp, I got following error message -
For now, I've removed the config.php settings and restored it to what it was earlier. Everything seems to be working fine now.
However, I wish to have memcached enabled on server without any problems. Can someone help me fix this?