Installing Memcache on Wamp 2.1e and Windows 7

Category: 

A Brief Description , Now a days lots of websites like Wikipedia, Twitter, Youtube, Digg are using an open source, high-performance, distributed memory object caching system called Memcache or Memcached. Basically it provides a caching mechanism in the server side scripting. Here we are going to use it for PHP. From there website it's quite understandable that the distribution is mainly built for Linux environment. But lot of people are very much comfortable using the Windows environment. In this "How to" I'll tell how to install memcache in Windows 7. I'm using the wampserver version "WampServer2.1e-x32". It has PHP 5.3 with it. Installation Steps,

Step 1.

First download the package memcached-1.2.6-win32-bin.zip from http://code.jellycan.com/memcached/ website or you can download it from Here.

Step 2.

Then unzip the file and you will get memcached.exe file. Place it in any desired directory. I've placed it in D:\wamp\bin directory in a folder called memcached. because my wamp is in D Drive. So the directory structure is like D:\wamp\bin\memcached.

Step 3.

As I'm using Windows 7 so I've to make that executable file run as Administrator. So to do that right click on the executable file and go to Compatibility tab. Near bottom you'll see Privilege Level, check "Run this program as an administrator".

Step 4.

Now it's time to install the application. So to do that, fire-up command prompt as an Administrative User in Windows 7 and then type the following command
  "your path to memcached.exe" -d install

For further help please refer to the image below.

Install Memcached Command Prompt

Here you can face a problem. When you hit enter after writing the install command a dialog box can pop-up and say, The program can't install because MSVCR71.dll is missing from your computer. Like in my case,

Error MSVCR71.dll

To solve this please download the MSVCR71.dll. You can google it if you want or else click Here to download the dll file. Paste it in C:\Windows\system32 folder and then hit enter again in the install command and you have successfully installed the memcache.

Step 5.

After installation start the service. Go to Run and type in services.msc to open the Services Window. Search for memcached Server and Start the service. Or if you like it in command line then, in Command Prompt type net start "memcached Server". You will see, the two confirmation messages and you are ready to go. Please follow the image below to more reference.
Memcached Service Windows

Step 6.

After all of these its time to let PHP know that you have installed it. So, check your php extensions directory for the php_memcache.dll. I think it won't be present there. So you have to manually download it also. Now here comes another problem. All the php_memcache.dll files available in internet ar of PHP 5.2 & PHP 5.2+ but not PHP 5.3. After lot of googling I've found a website, http://downloads.php.net/pierre/. Search for php_memcache and you will get two dll extensions.
  1. php_memcache-2.2.6-5.3-nts-vc9-x86.zip
  2. php_memcache-2.2.6-5.3-vc9-x86.zip

Again none of these worked for me. So again into Google. After spending lot of hours I've finally got one. I'm providing it Here,so click then link and download. After download place the .dll file in your PHP extension directory. Generally for wamp it's the wamp\bin\php\php5.3.5\ext\. Then Open up php.ini file and paste in the extension section, extension=php_memcache.dll and restart wamp.

Testing,

Run this code to test the installation. If you see anything but errors, you are now using memcache!

<?php
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect"); 
//Can Use 127.0.0.1 instead "localhost"
$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";
$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;
$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";
$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";
var_dump($get_result);
?>

 

Rate this content: 

Average: 4.9 (8 votes)

Comments

Thanks!

Thanks! Ran into a small problem but worked around it easily.

I found that I had to place the MSVCR71.dll into C:\Windows\system instead of C:\Windows\system32

After copying the dll into the system32 folder, The installer would still complain that it was not found. So, I tried to register it manually and it complained the dll wasn't compatible (using Win 7 64bit on a VM). Moving it to the system folder instead worked like a charm though.

Add new comment