Installing memcache on Windows for PHP
LAST UPDATED MAY 7, 2009
Installing memcache on Windows XP / Vista is kind of like voodoo for those of us who are not disciplined with compiling code from source. I initially attempted to install memcache a few months ago after reading a few articles about how much performance it can pump into your web application. The problem is that memcache was written with Linux in mind, not windows. So you can’t download any installers or exe files from memcache’s site for windows … which leaves people like me, who use WAMP stacks to develop applications, out in the cold.
So after a few hours of Googling I found a cocktail of methods and files to get memcache to work for win32.
A few things about memcache:
Memcache is a daemon, meaning it runs as a separate service on your machine. Just like MySQL runs as a separate service. In fact, to use memcache in PHP you have to connect to it, just like MySQL.
Think of memcache as the $_SESSION variable for PHP, but instead of it working on a per-user basis, it runs over the entire application — like MySQL. In fact, you can use memcache as you session handler for PHP.
This is how I got memcache to work on my windows machine:
- Download memcache from code.jellycan.com/memcached/ [grab the 'win32 binary' version]
- Install memcache as a service:
- Unzip and copy the binaries to your desired directory (eg. c:\memcached) [you should see one file, memcached.exe] – thanks to Stephen for the heads up on the new version
- If you’re running Vista, right click on memcached.exe and click Properties. Click the Compatibility tab. Near the bottom you’ll see Privilege Level, check “Run this program as an administrator”.
- Install the service using the command: c:\memcached\memcached.exe -d install from the command line
- Start the server from the Microsoft Management Console or by running one of the following commands: c:\memcached\memcached.exe -d start, or net start "memcached Server"
Now that you have memcache installed, you’ll have to tie it in with PHP in order to use it.
-
Check your php extensions directory [should be something like: C:\php\ext] for php_memcache.dll
If you don’t have any luck finding it, try looking at one of these sites:
- downloads.php.net/pierre/ [thanks to Henrik Gemal]
- pecl4win.php.net/ext.php/php_memcache.dll [currently down]
- www.pureformsolutions.com/pureform.wordpress.com/2008/06/17/php_memcache.dll for PHP 5.2.*
- kromann.info/download.php?strFolder=php5_1-Release_TS&strIndex=PHP5_1 for PHP 5.1.* [thanks, Rich] - Now find your php.ini file [default location for XP Pro is C:\WINDOWS\php.ini] and add this line to the extensions list:
extension=php_memcache.dll - Restart apache
- Run this code to test the installation: [found on www.php.net/memcache]
<?php $memcache = new Memcache; $memcache->connect("localhost",11211); # You might need to set "localhost" to "127.0.0.1" echo "Server's version: " . $memcache->getVersion() . "<br />\n"; $tmp_object = new stdClass; $tmp_object->str_attr = "test"; $tmp_object->int_attr = 123; $memcache->set("key",$tmp_object,false,10); echo "Store data in the cache (data will expire in 10 seconds)<br />\n"; echo "Data from the cache:<br />\n"; var_dump($memcache->get("key")); ?>
If you see anything but errors, you are now using memcache!
EDIT
Memcached, by default, loads with 64mb of memory for it’s use which is low for most applications. To change this to something else, navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\memcached Server in your registry, find the ImagePath entry and change it to look something like this:
“C:\memcached\memcached.exe” -d runservice -m 512
Now when you start the service via net start “memcached Server”, it will run with 512mb of memory at it’s disposal.
Thanks, its so useful!!
Hannan Nozari
February 12, 2008
any tips on how to increase max memory? -m in command line doesn’t seem to do it for me.
colum
March 4, 2008
colum,
I added to the post addressing the max memory.
pureform
March 4, 2008
Really very useful article.
I got everything .
Thank you very much.
bijul soni
April 21, 2008
Thank you – this is great!
Anastasia
May 14, 2008
[...] on May 21, 2008. Memcache is a great caching tool available for nearly every scripting or programming environment. I use it [...]
Using Memcache with MySQL and PHP « Adventures in PHP / DHTML / CSS and MySQL
May 21, 2008
Dude, thank you for this! I was stuck at 65Megs and couldn’t figure out how to change that setting. Thanks!
Tim Merrifield
June 11, 2008
The pecl4win.php.net site is down. Anyone know where I can find the windows binary for the pecl memcache client?
Derak
June 17, 2008
Try here: http://www.pureformsolutions.com/pureform.wordpress.com/2008/06/17/php_memcache.dll
This is 6 for PHP 5.2.6 [though it will probably work for 5.2.x]
pureform
June 17, 2008
I believe this is a more recent version of memcached for Win32.
David Kaspar
June 20, 2008
Bloody awesome guide, thanks mate, Me love you long time :P
Brett
July 10, 2008
Use the 1.2.5 binaries from here:
You can get a 1.2.5 binary here:
http://code.jellycan.com/memcached/
Or here:
http://code.google.com/p/beitmemcached/downloads/list
Both of these are much newer and most importantly remove a very troublesome problem with Memcached and Windows machines with multi-cores where one core would be eaten up by Memcached.
Stephen
July 31, 2008
thanks, very useful and simple manual!
Ika
August 26, 2008
thanks!
Gercek
August 26, 2008
Kudos, my friend. This was a great help :)
KevBurnsJr
September 12, 2008
Remember to use the non-thread-safe version of the pecl library if your php is non-thread safe, otherwise the dll won’t load [check using phpinfo()]
Nick Stanton
October 8, 2008
Thanks brad ! That’s a great useful work.
Hugues
October 8, 2008
Man this really rocked for me. I was hunting it down for months and got it now. Like you I have my test and development environment on my local PC which is windows and it was always difficult for me to test the things equally on my devel box and prod box :)
imoracle
October 15, 2008
Great jobs ! thanks a lot. Your tutorial is very clear.
quang
October 18, 2008
Thank you very much
kamlesh patidar
October 21, 2008
[...] XP: http://pureform.wordpress.com/2008/01/10/installing-memcache-on-windows-for-php/ This was written by dani. Posted on Monday, November 17, 2008, at 7:24 am. Filed under [...]
techlinks › Memcache
November 17, 2008
This didn’t work for me… I got a “failed to install service or service already installed” error on installation.
Furthermore, I got the latest version of memcache from Jellycan but it only includes the .exe file mentioned here, not the .dll.
No one else had this problem?
Lance Goodthrust
November 24, 2008
if you are missing this file MSVCR71.dll just like me then download it from: http://www.dll-files.com/dllindex/dll-files.shtml?msvcr71
It worked for me.
Aashish
April 23, 2009
r u sure u r executing first install command then start command?
i got the same error “fail to install service” then i realize i was directly executing start command without executing install command. make sure u have execute first install command
pradipinfo
May 27, 2009
Dude, you saved my lot of time!
Thank you so much.. it is really very worth information!
Dayananda MR
December 2, 2008
if you are trying to install memcached on windows vista, right click on the memcached.exe, go to its properties and make sure on the compatibility, run as administrator is selected.
good luck
quantize
December 9, 2008
Very helpful.Thanks for the guidence.
Azaad
December 18, 2008
Thanks a lot. Great job!
aaa
December 23, 2008
Hey! thank a bunch man!
was planning on experimenting with memcache for a while, but to lazy to figure out how to get it working on win32..
saved my day!
Zogs
January 7, 2009
greate article! thanks!!
manzuni
January 15, 2009
super super :)
ignis
January 29, 2009
Thanks You! Very much. It is very good article to install memcache in widows. It helps me a lot.
Anand Kumar
February 9, 2009
while restating the Apache after extension added I am getting following error in the error.log and extension not loading
PHP Warning: PHP Startup: memcache: Unable to initialize module\nModule compiled with module API=20050922, debug=0, thread-safety=1\nPHP compiled with module API=20060613, debug=0, thread-safety=1\nThese options need to match\n in Unknown on line 0
Please can anybody help me
Ramarao
March 16, 2009
Thanhk you
hoang nguyen
March 30, 2009
You can find a php 5.3 version of the memcache here:
http://kromann.info/download.php?strFolder=php5_3-Release_TS&strIndex=PHP5_3
Thiago Mata
April 17, 2009
php_memcache.dll can be found/downloaded here:
http://downloads.php.net/pierre/
Henrik Gemal
April 20, 2009
very detailed description.. very useful. saved lot of my time. thanks.
Aashish
April 23, 2009
How to install it in a IIS7.5 (w2k8 R2) which is only x64 not x86.
memcached.exe install fails looking for msvcr71.dll
Cheers!
crazy webmaster
April 24, 2009
Thanks a lot!
Pavel Petrov
April 27, 2009
I am running EasyPHP 2.0b1.
I installed memcached from the windows binary.
I started the memcached service and can telnet into it just fine.
The php_memcache.dll file is present in the ext directory.
The extension is enabled in php.ini and shows up with phpinfo().
I’ve tried turning off my firewall.
Still, I get this error when trying to connect from PHP:
Any suggestions would be greatly appreciated!
Eric
April 30, 2009
very helpful! thanks a lot
joe mak
May 1, 2009
OK, I changed
$memcache->connect(‘localhost’,11211);
to
$memcache->connect(‘127.0.0.1′,11211);
and it worked!
Eric
May 1, 2009
!st, This is my most favorite blog post in the whole internet – thank you and others who helped make a binary…
In general, is it ok or normal to install memcached on the webserver machine (localhost) or better to use on external machines in the same LAN ?
John A
May 6, 2009
Anyone know where I can find a .dll for PHP 5.3 ??
William Meyer
May 7, 2009
And I need one for PHP 5.1.6. . .
Rich
May 7, 2009
And I (finally) found one that worked here: http://kromann.info/download.php?strFolder=php5_1-Release_TS&strIndex=PHP5_1. Hopefully this will help someone else who can’t get memcached to load.
Rich
May 7, 2009
[...] статья — вольный перевод, оригинал: Installing memcache on Windows for PHP Эта запись была опубликована в Вторник 12-го Мая 2009 [...]
Q-Zma’s Burrow » Blog Archive » Установка memcache для PHP в Windows
May 12, 2009
Thanks mate, got it up and running in no time thanks to this guide
Carlton
May 14, 2009
[...] Thursday 14th May, 2009 Handy resource on installing memcache on windowsCheck out this website I found at here [...]
Installing memcache on Windows for PHP « Dasher’s Corner
May 14, 2009
[...] Installing memcache on Windows for PHP « Adventures in PHP / DHTML / CSS and MySQL [...]
Daily Digest for 2009-05-15 | Pedro Trindade
May 15, 2009
Awesome! This made setup a breeze!
Laran Evans
May 23, 2009
Скажите а материалы с Вашего сайта можно у себя размещать?
Futtjuiggitly
May 25, 2009
Very useful! Thanks
Nightfly
May 27, 2009
this document really rocking anyone can do this instalation .This really clear.nice .I am impressed .with out admin i did instalation
Rajasekhar
June 19, 2009
Something I found a while ago (sorry, I can’t remember where, so can’t give proper credit). Makes a “nicely” named service, and sets the max memory at 2gigs and port at (the default) 11211:
“sc create memcached11211 binPath= “C:\php\memcached\memcached.exe -d runservice -p 11211 -m 2048″ start= auto DisplayName= “MemCached 11211″
(you MUST put the little spaces after the “=” signs!)
This will register a service called “memcached 11211″, with auto start enabled, the DisplayName “MemCached 11211″ and the parameters in the binPath.
On a side note, we’re currently running Kenneth’s 1.2.4 Win32-preview build (http://www.splinedancer.com/memcached-win32/) in production with pretty heavy traffic (largest webshop in northern Europe), working great so far. Only problem we have detected is that the service refuses to stop, you must kill the process to stop it. Only a minor annoynance. :-)”
Dean Higginbotham
June 19, 2009
this article helped me a lot to install memcache.
thanks a lot…..
krishan
June 23, 2009
i downloaded the windows version but there is no memcached.exe file. Anyone else run into this issue?
yemmer
June 30, 2009
nevermind..i downloaded teh wrong file. doh.
yemmer
June 30, 2009
Great installation guide. Thanks for sharing with us.
Sastha L
July 13, 2009
thanks a lot! made it with some problems on W7 :)
metalpower
July 13, 2009
Its Done Boss, really working!!!
Jawwad Ahmed
July 13, 2009
Thanks, got me up and running in no time!
edanb
July 23, 2009
Thank you. Excellent!
Mitch
July 30, 2009
hi great post 10x, however i was unable to execte the example i am getting:
“Fatal error: Class ‘Memcache’ not found”
i added the dll to the ext list in the php.ini and restart apache with no luck please advise.
oded
August 3, 2009
You ought to check and see if the memcached extension is complied for the version of php you have installed… You can check apache’s error_log to see if that’s the issue. The files listed above are for php 5.1 and php 5.2, so if you’re running 5.3 or a 6.0 build, it wont work properly.
pureform
August 4, 2009
thanks for the help however i am using php 5.2.0 here are some more details that may shade some light.
running the phpinfo i get:
php version 5.2.0
system Windows NT USER-PC 6.0 build 6001
apache api version 20020903
i using Vista
where else should i check to get more details that may help to track the problem.
10x Oded
oded
August 7, 2009
I manage to work it out, it seems that PHP 5.2.0 cannot load the memcached dll, after upgrading to 5.2.10 everything went well.
Thanks for the help.
Oded
oded
August 8, 2009
great work!
Thank u so much.
millan
August 5, 2009
it’s the first tutorial about this topic, that really worked for me. thank you so much.
Karsten
August 6, 2009
Great article – thanks very much!
Paul
August 7, 2009
I’m looking for the PECL Win32 php_memcache.dll for PHP 5.3 I only found the one for PHP 5.2
Thanks!
Yago
September 4, 2009
tks for the post :D
Vu
September 7, 2009
Thank you for the fantastic Step by Step expanation.
The Links to the memcached.dll were just what I needed to make it work.
Thank you very much.
Hugo
September 10, 2009
thanks! nice tutorial
David
September 23, 2009
gee, thank u so much guys, my memcache is working now…
nurv7
November 7, 2009
wow!!!simply great, thanks alot, i really found it helpful. Can you write more examples of using memcached.
ravi
November 9, 2009