Shiki

I'm so bad with words that I can't even make a cool tagline

Installing Memcached for PHP 5.3 on Windows 7

Updated:

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.

Install memcached

  1. Download the Memcached Win32 library here: http://code.jellycan.com/memcached. Just get the Win32 binary (direct link). Extract the downloaded archive file in a directory (e.g. c:\memcached). There should be a memcached.exe in there.
  2. Run a command prompt as an administrator. Some info on how to do that here.
  3. Install memcached as a service. Go to the memcached directory, type and run:

    memcached -d install
    

    If you get an error saying “MSVCP71.dll is missing”, see this page for a solution.

  4. Start the memcached service by running:

    memcached -d start
    
  5. You can verify if memcached is running by executing this in the command line:

    wmic process get description, executablepath | findstr memcached.exe
    

    You should see a result list showing memcached.exe and its full path.

Install PHP Memcache extension (php_memcache.dll)

  1. Chances are you don’t have php_memcache.dll in your PHP extensions yet. You can download a build of it here. Basu has noted in the comments that VC6 builds are no longer available from that link. You can download the correct build here.
  2. The archive should contain php_memcache.dll. Extract the archive to your php extensions directory. On my system (WampServer), this was C:\wamp\bin\php\php5.3.0\ext.
  3. Edit php.ini, add this line to enable the extension:

    extension=php_memcache.dll
    

    Or if you’re using WampServer, restart it and enable the extension through the WampServer system tray menu.

Test

Test the installation using the sample PHP code here: http://www.php.net/manual/en/memcache.examples-overview.php.

80 Responses to Installing Memcached for PHP 5.3 on Windows 7

this is sucks, the php client library is not memcacheD its just ‘memcache’ (without D), if any of you find this fucking D please let me know.

Hi there, Also after providing my code.google.com password, it says I don’t have permission to access the file :(

@orlando: That fracking D is Linux-only extension since it utilizes “libmemcached” component which is a Linux-specific thingie… So, no luck there.

Thanks for the post. I have installed the memcache and php extension. But when I tried the example like getVersion it returnes nothing. $memcache = new Memcache; // instantiating memcache extension class $memcache->connect("127.0.0.1",11211) or die ("Could not connect"); // try 127.0.0.1 instead of localhost // if it is not working

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

This gives me the following result. Can you help me?

Memcache Object ( [connection] => Resource id #3 ) Server version:

That is memcache is installed. But the getVersion is not working?

@Shihab hmmm.. sorry I’m not exactly sure what’s wrong. Everything’s working fine on my end. But are the $memcache->set() and $memcache->get() methods working though?

When I tried by enabling the error logging with error_reporting(-1); ini_set('display_errors', true);

I got the error Notice: Memcache::getversion() [memcache.getversion]: Server 127.0.0.1 (tcp 11211) failed with: Failed reading line from stream (0) in …

I suppose the problem is in memcached.exe then. Can you confirm that memcached is running? You can test it by executing this on the console:

wmic process get description, executablepath | findstr memcached.exe

I really like this site bcoz it help me to start memcached in my localhost . u must see it is great

Where can i find the installed memcache server and what is remaining storage area? Simply i want to know benchmark.

Thanks for that entry, it helped me getting through the installation process the short way, with XP and VC6 builds however, so especially thanks for that vc6-download link.

Thank you! This is exactly what I needed to get memcached going.

Does anyone know how to SET the amount of memory that memcached will use? On my Linux server, I can start it with the “-m 256″ option to give it 256 Mb. How can I do the same on a Windows 7 box where the o/s starts the service automatically. I have not yet found where I have access to change the startup command it uses.

Thanks!

Unable to run the example every other thing seems fine but when I try to run it says, Class Memcache not found. seems like extension is not enabled but have checked php.ini and ext folder as well, may be wrong extension was downloaded can some one let me know which extension file i need,

php 5.x, windows 7(64 bit), apache, (no xamp, no wamp), downloaded binaries of memcached server. please help

Hi Mubashar, it’s probably because you’re on 64 bit Windows. I’m not sure if this will work on that.

Thank you very much for the info.

First when I tried it was giving a error ‘Fatal error: Class ‘Memcache’ not found’.

Following this post, I realized I have used the wrong dll file. i was using vc9. Now I am using vc6 and no errors. :-)

Thank you! I really appreciate your effort in making this post. I’m stuck at making this memcached work on windows, and then I found your awesome blog at stackoverflow.

I have placed the php_memcache.dll in extension directory and placed the relevant code in PHP.ini

But After this my apache is not starting. Any thing I am missing?

@Avinash I currently don’t have an idea what could be missing. But I would check Apache’s error log. There might be some clues in there.

php code to test:

connect('localhost', 11211) or die ("Could not connect");

$version = $memcache->getVersion(); echo "Server's version: ".$version."\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)\n";

$get_result = $memcache->get('key'); echo "Data from the cache:\n";

var_dump($get_result);

I am using WAMP on windows7 .My php code connect(“localhost”,11211)or die (“Could not connect”); // try 127.0.0.1 instead of localhost $testArray = array(‘horse’, ‘cow’, ‘pig’); $tmp = serialize($testArray); $memcache->add(“key”, $tmp, 30); echo “Data from the cache:\n”; print_r(unserialize($memcache->get(“key”))); ?> is working absolutely fine but instead of memcache class i want to use memcached class i.e. $memcache = new Memcached; it is giving me class Memcached not found.Please help me what other changes i have to make? Thanks Nehaa

thanks for sharing this. actually i need help. i installed memcached and it is started. but when i check my code it says “Class ‘Memcache’ not found” . please help me.

Im unable to install memcache in windows 7 , 64 bit could you please provide more information. when i check incompatibility, it shows up to windows xp.

Thanks in advance.

Sorry for the ast post

Im unable to install memcache in windows 7(64 bit). Could you please provide more information. when i check compatibility, it shows up to windows xp.

Thanks in advance.

thanks for u r hep, it is a permission problem in windows 7, I copied file into windows\system32 folder and run from command prompt as Administrator

Thank you! Worked fine for me. But, i need memcached, if yo have any idea, Could you please help me.

Thanks In advance

@sundar Sorry I tried looking for a memcached dll before but could not find any. I’m not sure if it is even available on Windows.

Hey there,

For windows 7, 64 bit right click on the exe and select properties. Under the compatibility tab check “Run this program as an administrator” and then follow the process from the start. You should get the pop-up warning that it’s going to make changes to the system to let you know that it’s going to work.

Later,

Matthew

I had the “PHP Fatal error: Class ‘Memcache’ not found” error too which is a vc version mismatch between php distribution and module

C:\Users>php-cgi.exe -b 127.0.0.1:9000 PHP Warning: PHP Startup: memcache: Unable to initialize module Module compiled with build ID=API20090626,TS,VC6 PHP compiled with build ID=API20090626,TS,VC9 These options need to match in Unknown on line 0

I solved it by downloading and installing the vc9 version from the old page:

http://downloads.php.net/pierre/php_memcache-2.2.6-5.3-vc9-x86.zip

If you have nts php distribution then maybe you need:

http://downloads.php.net/pierre/php_memcache-2.2.6-5.3-nts-vc9-x86.zip

Shiki, thanks for this article!

i got this error

Fatal error: Class ‘Memcache’ not found in F:\wamp\www\testmem\one.php on line 3

what is the problem?

Hi! Thanks for your post. Its helpful. But I am wondering is there a memcached.dll available? Or is it only for servers based on Linux? Thanks.

Hi Friends,

I have coded a Session Handler for my website but when i am working on it. The site is showing an error below: - SCREAM: Error suppression ignored for ( ! ) Fatal error: Interface ‘SessionHandlerInterface’ not found in C:\wamp\www\Anon Shoppe.com\website_development\WWW\controller\session_handler.php on line 10

I don’t know what is wrong, i have installed memcache also. then also its not working. Can anyone help me? I really need it.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>