Installing memcache on Windows for PHP

Posted on January 10, 2008. Filed under: Apache, Memcache, PHP | Tags: , , , , , |

LAST UPDATED SEPTEMBER 11, 2010

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:

  1. Download memcache from code.jellycan.com/memcached/ [grab the 'win32 binary' version]
  2. 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.

  1. 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]
  2. 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
    
    
  3. Restart apache
  4. 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.

EDIT

[Thanks to Travis]
If anyone is wondering what other options can be set (other than the memory limit), run “memcached -help” in a command prompt window. Then modify the ImagePath command line per this article with the desired switches and values.

About these ads

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

172 Responses to “Installing memcache on Windows for PHP”

RSS Feed for Adventures in PHP / DHTML / CSS and MySQL Comments RSS Feed

Thanks, its so useful!!

any tips on how to increase max memory? -m in command line doesn’t seem to do it for me.

colum,

I added to the post addressing the max memory.

Really very useful article.
I got everything .
Thank you very much.

Thank you – this is great!

[...] on May 21, 2008. Memcache is a great caching tool available for nearly every scripting or programming environment. I use it [...]

Dude, thank you for this! I was stuck at 65Megs and couldn’t figure out how to change that setting. Thanks!

The pecl4win.php.net site is down. Anyone know where I can find the windows binary for the pecl memcache client?

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]

Bloody awesome guide, thanks mate, Me love you long time :P

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.

thanks, very useful and simple manual!

Kudos, my friend. This was a great help :)

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()]

Thanks brad ! That’s a great useful work.

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 :)

Great jobs ! thanks a lot. Your tutorial is very clear.

Thank you very much

[...] 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 [...]

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?

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.

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

I had the same problem. Running the command prompt as an administrator before doing the install fixed the issue.

This helped me, thank you

thanks Jeff. u saved my time!

Dude, you saved my lot of time!
Thank you so much.. it is really very worth information!

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

Very helpful.Thanks for the guidence.

Thanks a lot. Great job!

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!

greate article! thanks!!

super super :)

Thanks You! Very much. It is very good article to install memcache in widows. It helps me a lot.

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

php_memcache.dll can be found/downloaded here:

http://downloads.php.net/pierre/

very detailed description.. very useful. saved lot of my time. thanks.

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!

Thanks a lot!

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:

Warning: Memcache::connect() [function.Memcache-connect]: Can’t connect to localhost:11211, 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)

Any suggestions would be greatly appreciated!

very helpful! thanks a lot

OK, I changed
$memcache->connect(‘localhost’,11211);
to
$memcache->connect(‘127.0.0.1′,11211);
and it worked!

!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 ?

Anyone know where I can find a .dll for PHP 5.3 ??

And I need one for PHP 5.1.6. . .

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.

[...] статья — вольный перевод, оригинал: Installing memcache on Windows for PHP Эта запись была опубликована в Вторник 12-го Мая 2009 [...]

Thanks mate, got it up and running in no time thanks to this guide

[...] Thursday 14th May, 2009 Handy resource on installing memcache on windowsCheck out this website I found at here [...]

[...] Installing memcache on Windows for PHP « Adventures in PHP / DHTML / CSS and MySQL [...]

Awesome! This made setup a breeze!

Скажите а материалы с Вашего сайта можно у себя размещать?

Very useful! Thanks

this document really rocking anyone can do this instalation .This really clear.nice .I am impressed .with out admin i did instalation

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. :-)”

this article helped me a lot to install memcache.
thanks a lot…..

i downloaded the windows version but there is no memcached.exe file. Anyone else run into this issue?

nevermind..i downloaded teh wrong file. doh.

Great installation guide. Thanks for sharing with us.

thanks a lot! made it with some problems on W7 :)

Its Done Boss, really working!!!

Thanks, got me up and running in no time!

Thank you. Excellent!

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.

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.

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

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

great work!

Thank u so much.

it’s the first tutorial about this topic, that really worked for me. thank you so much.

Great article – thanks very much!

I’m looking for the PECL Win32 php_memcache.dll for PHP 5.3 I only found the one for PHP 5.2
Thanks!

tks for the post :D

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.

thanks! nice tutorial

gee, thank u so much guys, my memcache is working now…

wow!!!simply great, thanks alot, i really found it helpful. Can you write more examples of using memcached.

thank you for this tutorial…
it really saved me a lot of time

Thankssssss its helped sooo much

[...] Installing memcache on Windows for PHP [...]

[...] MacOSXで開発したいと思いつつ、会社ではWindowsでもやらないといけない。 Windowsでphp-memcacheを使えるようにしてみた。なお、サーバはLinuxなのでライブラリを入れるだけ。 xamppの最新版はMTの開発にいいかも。的な記事を書こうとして書いてないのでまた書こう。 どうもWindowsではPECLでインストールするのが具合がわるいらしいので直接php_memcache.dllを落としてextensionディレクトリに突っ込むのがよいらしい。 参考: http://pureform.wordpress.com/2008/01/10/installing-memcache-on-windows-for-php/ [...]

Thanks a lot, men!
Tutorial is simple and great!
I installed memcached just as you said, and it works!
Thanks!

This is awesome! Thanks.

I am really thankful to you.

u saved a lot of time.

None of these DLL’s work with that binary.

Ok so I just checked, I’m using 5.3.0 and its not working, any ideas?

Really very helpful, Thank you

thank you very much, that was very useful

I have a weird problem. My Memcached works fine, I’ve managed to test it. Weird thing is that I have to call getVersion() function before I can fetch data from cache. I’ve tried it with and without the function. Any idea what could cause it?

[...] off, all credits go to this guy. I’m just listing the steps on how I did it in Windows 7 with PHP 5.3. Also, I tested this [...]

Thanks! For others having problems installing memcached, try running the command prompt as an administrator.

[...] Installing memcache on Windows for PHP « Adventures in PHP / DHTML / CSS and MySQL (tags: php windows memcached howto) [...]

Thank you for your post. It saved me a lot of time.

Great article.

After setup, I found that set to memcache always return false. Is there any idea to troubleshoot this issue?

i have the same problem. When i set to memcache, sometimes it shows message, Notice: Memcache::set() [memcache.set]: Server 127.0.0.1 (tcp 80) failed with: Failed reading line from stream (0). But sometimes not. When I get values, it always return false.

[...] may help http://pureform.wordpress.com/2008/0…ndows-for-php/ __________________ Do not ask me to help you work on your site that is not phpMyBitTorrent Do [...]

If I install memcache 1.2.6 at my windows apache php 5.2 build 3790 system I get always this php error:
PHP Warning: PHP Startup: Unable to load dynamic library ‘c:\PHP5\ext\php_memcache52.dll’ – Die angegebene Prozedur wurde nicht gefunden.
in Unknown on line 0

But the dll is there. And I tried every windows php_memcache.dll version from pierre – Does anybody knows what to do. Would be great if yes!

Thx in advance!

cheers,
Tom

Nice info,,Thank’s

Thank you so much. Everything works great with the latest php 5.3.2

I’m trying to install this for php 5.3.3. I’m having no luck. If I add the extension to php I get a server fault when trying to start apache. No error in the log, no explanation whatsoever, just can’t start it. I’m using the memcache-cvs-5.3-VC6 dll.

It’s still work at IIS 7 !!

Thank you ever so much!

Ey can i have some help? did everything wht was writen down but its not working, im running appserv and everytime i get this: Fatal error: Class ‘Memcache’ not found in C:\AppServ\www\test.php on line 2

my PHP Version is 5.2.6 i tried everything but its not working, can someone give me a hint?

[...] binaries for memcached from Jellycan Code | memcached. Thanks! Then I found this great post titled Installing Memcache On Windows For PHP which was a big help. I followed the link to here to get the cvs 5.3 version of the PHP extension [...]

Thanks a heap. You saved me the trouble of compiling the memcache module myself.

I need the memcache dll for php 5.2.0.
No one is working.
Does anybody know where to get the memcache dll for 5.2.0?
thanks in advance!
Best
Michael

[...] Installing memcache on Windows for PHP – a blog post explaining something similar to what I just did [...]

Hello

Very useful article. Does the php.ini file require any configuration parameters to recognise memcache? Followed your article but couldn’t see Memcache listed by phpinfo().

I’m attempting use Memcache with PHP5.3.1.

I’m not sure if it does. I was able to run it without doing any extra config.

Did you try the 5.3.x extension from this site? http://downloads.php.net/pierre

If anyone is wondering what other options can be set (other than the memory limit), run “memcached -help” in a command prompt window. Then modify the ImagePath command line per this article with the desired switches and values.

Great starter tutorial.This helps a lot. Thanks :)

i could not navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\memcached Server, can anyone explain me how this can be done

Good one.

[...] to Travis] If anyone is wondering what other options can be set (other than the memory limit), run [...]

[...] Yii framework: WAMP için memcache kurulumu. Yii gereksinimlerine baktığımızda memcache eğer WAMP kullanıyorsanız memcache için warning uyarısı çıkacaktır. Yukarıdaki linkteki kurulumu yaparak bu uyarıyı kaldırabiliriz. AKPC_IDS += "143,";Popularity: unranked [?] [...]

nice post guy, thank you

nice tutorial!10xs

[...] – Today, 01:55 PM I installed the memcached daemon on windows by following this link: Installing memcache on Windows for PHP Adventures in PHP / DHTML / CSS and MySQL Works like a charm! Now it's MUCH [...]

This article was very helpful, well writen and straight to the subject. Thanks a bunch, as this is going to have imediate use.Thumbs up!!!

First, this is a nice howto :-)
Second, nothing works for me, the Memcache Class can’t be found. I use Windows 7 Pro with PHP 5.3.5 and get the Jellycan Code’s memcached Version 1.2.6 and later 1.2.5. The memcached.exe has admin-rights and i set temporarily the XP/Vista compatibility. Memcached runs as Service and the php.ini has the extension enabled.

All setting configuration are correct. Does anyone have any idea what I could still try?

Yes, all of them and all the dlls from other published links from the comments.

I don’t think i have the Ultimate-Special-System wich Memcached won’t work :-)

I have some error while restart the apache..
i am
Using
OS:Windows Xp;
PHP:PHP Version 5.3.2
Apache:Apache/2.2.17

Hi,

I have to use memcached not the memcache.
new Memcached()
php_memcache.dll does not support the memcached. can you help me to run Memcached please.

I am using WAMP server within windows 7.

Dude, thank you for this!

Hi,
i tryed to install via:
memcached.exe -d install but i get this error:
“Failed to ignore SIGHUP: Invalid argument”

hm, any ideas?

best wishes
Michael

I got the “SIGHUP” error, too. Using memcached 1.4.4 that I got from here fixed the issue for me.

My blog has opened so many doors for me and has helped me land quite a few jobs. By being immersed in writing and showing initiative, having a blog has been a great platform and portfolio. And I would recommend to anyone looking to start or build a portfolio to have a blog.

Receiving Fatal Error: class Memcache not Found.

Thanks for the info.

First when I tried this it was giving a error ‘Fatal error: Class ‘Memcache’ not found’
Then I realized the dll I have used is wrong.
I was using V9 version but now I use V6.

http://shikii.net/blog/downloads/php_memcache-cvs-20090703-5.3-VC6-x86.zip

Now no errors.
I am using Windows 7, apache server XAMPP

Hope this will help anyone having the same issue.

Hello.
PHP Version 5.3.5
PHP API 20090626
PHP Extension 20090626
Zend Extension 220090626
Zend Extension Build API220090626,TS,VC6
PHP Extension Build

Where can i find the right php_memcache.dll? When i try to start apache, there comes the error that the module is not compiled with the right php build.

MFG Daniel

Thanks for sharing, good job!! :D

Are all the projects implied kept compatible withj windows?

thanks.really liked the article, but somehow cant connect to the memcached server yet despite I can see its running through command prompt and memcache extension dll also added. any clue??

Great, thanks alot for this…I found that I was having problems until i saved the memcache.exe file to a directory named memcached in the xampp directory (ie. NOT C:memcached BUT C:xampp\memcached)…hey, maybe thats just me being a t**t!

this is memcache!!!!!!

[...] I came across this blog post, which not only tells you how to to install the extension (adding 1 line to your [...]

Thanks, I have been reading a lot tutorials but no one says something basic like you did… run cmd.exe as administrator, so thanks very much it worked!

Thank you very much sir

Hi,

Thanks a lot its really very helpful,

It’s Working like a charm

Thanks again
Harsh

I still found this useful, I’m grateful to you!

[...] MEMCACHED ON AMAZON LINUX AMI — QUICK AND EASY. INSTALLING MEMCACHED ON Windows. install Memcached on Xampp on Windows 7 Memcached for PHP 5.3 on Windows [...]

i wonderd why this is not work for me. i am getting this error: “Fatal error: Class ‘Memcache’ not found” but the service is started correctly and i did all you thought. what can i do?
thanks

i am using apache v2.2.21 and php v5.3.9 .

[...] follow the links. php_memcache.dll INSTALLING MEMCACHED ON AMAZON LINUX AMI – QUICK AND EASY.INSTALLING MEMCACHED ON Windows.install Memcached on Xampp on Windows 7Memcached for PHP 5.3 on Windows [...]

[...] voor Linux, er bestaan dus geen kant-en-klare installers voor Windows. Ik volgde hierbij deze tutorial. Na heel wat gepruts vond ik het correcte DLL bestand en kon ik gaan cachen in PHP. Het volgend [...]

[...] INSTALLING MEMCACHED ON Windows. [...]

thanks

Superb, thanks.

Quick note – I’m using WAMPServer 2.1 on Windows 32-bit, and I had to use a different version of php_memcache.dll:

http://shikii.net/blog/downloads/php_memcache-cvs-20090703-5.3-VC6-x86.zip

Found it through Stack Overflow (bless ‘em)

[...] 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 StartedThe first thing [...]

Class ‘Memcache’ not found is that the error he is talking about?

[...] off, all credits go to this guy. I’m just listing the steps on how I did it in Windows 7 with PHP 5.3. Also, I tested this [...]

Nice post. This excellent website truly has all of the info I wanted about this subject and didn’t know who to ask. realy Good post. thanks so much.

[...] 1、《INSTALLING MEMCACHED ON Windows.》, 2008,1.10 [...]

[...] INSTALLING MEMCACHED ON Windows. [...]

Fiuh you’ve saved my works

[…] First off, all credits go to this guy. I’m just listing the steps on how I did it in Windows 7 with PHP 5.3. Also, I tested this using WampServer but I believe it should work on any PHP install. […]

I wish learned this long time ago. I received two job offers with this skill.

I update the post with new link for windows 8/8.1 and for php 5.2-5.5

http://www.kapadiya.net/blog/installing-memcached-windows-8-81/

Hello there! Do you know if they make any plugins to assist with SEO?

I’m trying to get my blog to rank for some targeted keywords but I’m
not seeing very good success. If you know of any please share.

Many thanks!


Where's The Comment Form?

Liked it here?
Why not try sites on the blogroll...

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: