2

i installed memcached and I also started the service by typing net start "memcached Server" and it said the service already started so i restarted apache and tried a couple of codes for using memcached:

<?php
//phpinfo();
$memcache = new Memcache;
$memcache->connect("localhost",11211); //change if necessary

$tempArray = array('fish', 'cow', 'demon');
$temp = serialize($testArray);

$memcache->add("key", $temp, 60);
print_r(unserialize($memcache->get("key")));


?>

but it gives an error:Fatal error: Class 'Memcache' not found in C:\wamp\www\temp.php on line 3 does this mean memcache is not started or anything else? i have not done anything except installing and starting the service do i need to do anything else like specifying The RAM and adding the server or anything else? I am using wamp server.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • Permissions? Try opening the command prompt as Administrator – tigrang May 30 '12 at 02:12
  • `phpinfo();` and look for `memcache` extension installed. After you'll have seen there is no any - check wamp documentation about how to install it. – zerkms May 30 '12 at 04:20
  • it didn't gave anything, only little bit of information but memcache is not written anywhere.......please help me out... –  May 30 '12 at 04:22
  • as I said: "**check wamp documentation about how to install it**" – zerkms May 30 '12 at 04:22
  • here is a simple example with php, memcached and wamp http://blog.webtech11.com/2012/02/07/caching-mysql-result-with-memcache-and-php.html – jogesh_pi May 30 '12 at 04:49
  • @NishchalGautam I see you unaccepted my answer. Let me know what you're having trouble with. – Paul May 30 '12 at 05:02
  • i wrote the following quotes: `connect("localhost",11211); //change if necessary $testval ="nishchal"; $memcache->add("key",$testval,true,360000); $v=$memcache->get("key",true); echo $v; ?>` but it gave me the output only: 'N;' without quotes so i dont know what to do –  May 30 '12 at 05:07
  • 1
    Isn't this a dup of the [same question](http://stackoverflow.com/questions/10809101/memcache-not-working-on-windows-7) you asked two hours earlier? Best to roll it into one question, I think. – halfer May 30 '12 at 12:00
  • @halfer I merged that one into this one (as this one is the better question) – Tim Post Jun 01 '12 at 08:44

4 Answers4

5

Here are the steps that worked for me:

Url: How to enable memcache in WAMP

Needed Files

memcached.exe Direct Link
MSVCP71.DLL Windows DLL Files
msvcr71.dll
php_memcache.dll Working memcache for PHP 5.3.4

Steps

Copy MSVCP71.DLL, msvcr71.dll to C:\windows\sysWOW64
Copy memcached.exe into C:\memcached
Click Windows-Key
Type: CMD
press: Ctrl-Shift-Enter
Choose yes
type: C:\memcached\memcached.exe -d install
type: C:\memcached\memcached.exe -d start
Copy php_memcache.dll to C:\wamp\bin\php\php5.3.4\ext
Restart Apache using Wamp controls
Enable WAMP -> PHP -> PHP Extensios -> php_memcache

Then, I hit the phpinfo(), it wasn't display the memcache property. Any one can help me to install the wmap.

-- Thanks D.Jeeva

Community
  • 1
  • 1
Jeeva
  • 92
  • 2
2

Make sure you run the command prompt as an administrator as well if you aren't already. Also ensure that you have memcache enabled and that you have the proper dll. Use phpinfo() to check that memcache is enabled PHP side. Then just run a quick script to test if memcache is operational. Try the following, if you don't get hit with errors memcache is enabled.

<?php
$memcache = new Memcache;
$memcache->connect("localhost",11211); //change if necessary

$tempArray = array('fish', 'cow', 'demon');
$temp = serialize($testArray);

$memcache->add("key", $temp, 60);
print_r(unserialize($memcache->get("key")));
?>
Johnnyoh
  • 369
  • 1
  • 7
  • when i run command prompt as an administrator, and run dir command, it gives this error message in place of every files and folders:`the system cannot find message text for message number 0x2355e in the message file for application. so i still went ahead... and executed the following set of commands: `c:\memcached\memcached.exe -d install c:\memcached\memcached.exe -d start` and i restarted my service and then when i tried your script, it gave me this error: ` Fatal error: Class 'Memcache' not found in C:\wamp\www\temp.php on line 2` –  May 30 '12 at 02:38
  • Are you using a copy of cmd or did you rename it? That error message should not be related to memcache in any way. Also, make sure that the proper extensions are being used, there are PHP extensions for both memcache and memcached. Use phpinfo() to verify that the correct one is enabled. If it is and you have the daemon running it should just work after a restart. – Johnnyoh May 30 '12 at 02:47
  • no i am not using copy and i didnt renamed it, when i installed memcached, it didnt showed any error and i started it too. phpinfo() didnt gave me any information about memcached.... @johnnyoh –  May 30 '12 at 03:16
  • can you please teach me how to install that? from the very beginning... @Johnnyoh –  May 30 '12 at 03:18
  • Heading off to work, but this tutorial should be sufficient. If you still have issues I'll try to help out when I get back. http://www.codeforest.net/how-to-install-memcached-on-windows-machine – Johnnyoh May 30 '12 at 10:47
  • @NishchalGautam: _from the very beginning_ - that's not really the approach we take on StackOverflow. We encourage people with hints and tips, and then expect them to do some independent web searching around the problem, so they learn how to solve problems themselves. If you're a beginner then searching for a tutorial (_php memcache tutorial_) is the way to go. – halfer May 30 '12 at 12:09
1

The Memcached service is not enough. By itself it has nothing to do with PHP and is not easily usable from PHP. To make it usable by PHP you also need either the Memcache or Memcached PHP extension which will handle communication with the service. It looks like you intend to use Memcache.

The PHP manual explains how to install PECL extensions on windows. WAMP may have an easier mechanism, I'm not sure as I'm not familiar with WAMP.

Edit

I found this blog post about installing Memcached to work with PHP on WAMP though. It could prove helpful. It looks like the extension is probably already available as a .dll file on your computer somewhere, and you just need to edit your php.ini file to include the extension and then restart Apache.

Paul
  • 139,544
  • 27
  • 275
  • 264
1

I faced the exact same issue.

In my case the problem was that i was running on a 64-bit system but i downloaded the 32-bit memcache dll file. After I downloaded Memcache 2.2.6 VC9 x64 Thread Safe

Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107
Memos
  • 464
  • 3
  • 9