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):
- If you’re running Vista, you should set memcached.exe to Run as administrator
- Install the service using the command: [code lang=”html”]c:/memcached/memcached.exe -d install[/code] from the command prompt
- 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”]
<?php
$memcache = new Memcache; // instantiating memcache extension class
$memcache->connect("localhost",11211); // try 127.0.0.1 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";
print_r(unserialize($memcache->get("key")));
?>
[/code]
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
Geez, everytime I see blogs this good I just want mine to be there already! 🙂 Great work.
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
@Isaac do you get an error trying the example code? What error is it?
Nice Article . i’ll try this in the afternoon today . 🙂 Even Facebook use memcache . The other day , i got a memcache error from facebook . i even took a screenshot 😉
http://i25.tinypic.com/6xzy83.png
PS : They are on Linux !
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.
Thanks
Sush
I’ve followed the steps above but i got the error: Class ‘Memcache’ not found.
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
Hi Rama,
thanks for your comment.
Setting 512 Mb limit for memcached means that a maximum of 512 Mb can be used by it.
Pingback: Memcached Overview : Max Ivak Personal Site
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”
Cheers!
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:
downloads.php.net/pierre/
After that add this line into your php.ini:
extension=php_memcache.dll
under extensions.
Restart Apache and you’re done.
I hope this helps and thank you for the comment.
Pingback: Memcached with Windows : Max Ivak Personal Site
Pingback: Installing memcached on Windows | barrylavides
Comments are closed.