Skip to content

How to install Memcached on Windows machine

After some research I found that there is a Win32 binary version of memcached available here.

So go there and download win32 binary version to your computer. When downloaded, extract the file to folder memcahced on your C partition.

You should get only one file named memcached.exe. Now we need to install this as a service, as memCached is daemon and should be run only as service.

To install Memcached as a service, follow these steps (please change all forward slashes to backslashes):

  1. If you’re running Vista, you should set memcached.exe to Run as administrator
  2. Install the service using the command: [code lang=”html”]c:/memcached/memcached.exe -d install[/code] from the command prompt
  3. Start the server from the Services or by running one of the following commands: [code lang=”html”]c:/memcached/memcached.exe -d start[/code] or [code lang=”html”]net start "memcached Server"[/code]

That is it, now your memcached server is installed and is listening to port 11211. There is one more thing left to do. By default, server is set to 64Mb memory limit, which is too small. To correct, go to Registry Editor and find key [code lang=”html”]HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/memcached Server .[/code]

Change the ImagePath entry to:
[code lang=”html”]“C:/memcached/memcached.exe” -d runservice -m 512[/code]

This way you will use 512 Mb memory limit for your server.

If you are using WAMP, then just turn on php_memcache extension in it. Now we are ready to go testing.

The simplest test is to write something to memcache that will expire in 30 seconds, and then try to retrieve the value from cache.

So write this into your test file:

[code lang=”php”]
$memcache = new Memcache; // instantiating memcache extension class
$memcache->connect("localhost",11211); // try instead of localhost
// if it is not working

echo "Server’s version: " . $memcache->getVersion() . "<br />\n";

// we will create an array which will be stored in cache serialized
$testArray = array(‘horse’, ‘cow’, ‘pig’);
$tmp = serialize($testArray);

$memcache->add("key", $tmp, 30);

echo "Data from the cache:<br />\n";

If everything went ok, you should see your array written out of memcache. Now you can use this powerful caching mechanism to develop really fast PHP applications. If you need to know more, go to PHP manual Memcached page

13 thoughts on “How to install Memcached on Windows machine”

  1. Geez, everytime I see blogs this good I just want mine to be there already! 🙂 Great work.

  2. Thank you for this article. I have been trying for a week to get Memcached (notice that this is not the same as Memcache) running on Windows. I have probably seen a thousand blogs and forums and everyone seems to use the two terms interchangeably.

    I have done what you just described above about 100 times (from other sites) and it just doesn’t work for me.

    I’m running WAMP Windows 7, Apache 2.2.11, PHP 5.3 – Nothing is working, please help me out. I know that I’m missing something obvious, please walk me through as if you were explaining it to a 2 year old.

    Thanks in advance

  3. Hi Zvonko,
    I am in the same place where Issac was.
    When i run this code it gives me this error.
    “Memcache::connect() [memcache.connect]: Server localhost (tcp 11211) failed with: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060) ”
    I am also using Wamp and same php and apache version but dint able to figure out what is wrong.



  4. Hi Zvonko,
    Thanks for the article.
    It is the same as I read on the book of Drupal 6 Performace Tips (PACKT publishing).
    For those who get error, you may want to read this book.
    I got the same error and found out that the memcache service is not running yet.

    Zvonkso, my question is if we set 512M for the memory limit, what does it mean?
    Does it set the fix memory for memcache only and can not be used for other application? or just the maximum limit?
    My server has 2 GB of RAm but it is used by all applications (XAMPP, Jetty and also chat server).
    Thanks for your answer

    1. Hi Rama,

      thanks for your comment.

      Setting 512 Mb limit for memcached means that a maximum of 512 Mb can be used by it.

  5. Pingback: Memcached Overview : Max Ivak Personal Site

  6. Hi! Thanks for the great article. Everything worked until:

    “If you are using WAMP, then just turn on php_memcache extension in it. ”

    How exactly do I do this?

    Looked inside httpd.conf and php.ini and found no such string to “turn on”


    1. Hi

      Check your php extensions directory [should be something like: C:wampphpext] for php_memcache.dll
      If you don’t have any luck finding it, download it from here:

      After that add this line into your php.ini:
      under extensions.

      Restart Apache and you’re done.

      I hope this helps and thank you for the comment.

  7. Pingback: Memcached with Windows : Max Ivak Personal Site

  8. Pingback: Installing memcached on Windows | barrylavides

Comments are closed.