20

I installed memcached by reading this article on Windows7 but unfortunately i keep getting error Fatal error: Class 'Memcache' not found in D:\xampp\htdocs\test\memcache\test.php on line 2

Line 2: $memcache = new Memcache;

Win7 64, Xampp Installed. I am using net start "memcached Server" on command line but it says service is already started.

Some other info which may help;

On php.ini file:

extension=php_memcache.dll

    [Memcache]  
    memcache.allow_failover = 1  
    memcache.max_failover_attempts=20  
    memcache.chunk_size =8192  
    memcache.default_port = 11211  

Update: phpinfo(); show dll is not loaded. Tried several different dll files so far, didn't work. Also dll is located correct. It is in the right folder as it seems.

(P.S. Some may think there are possible duplicates about this topic but there is only 1 person who followed the same instructions and had same error in SO. That question has no answer or solution since march.)

Community
  • 1
  • 1
Mustafa
  • 825
  • 3
  • 14
  • 37
  • 6
    Do you actually have `php_memcache.dll` in php extensions folder? – favoretti Aug 09 '12 at 12:28
  • 4
    The error isn't the memcached server, but is php config. Run php info to see if the dll is loading. You have restarted server since the config change? Another thing to check is that you are using dlls that are all 64 bit (I actually run 32 bit as it's easier to find and get right, but just make sure it's all one or the other). Check Apache logs for start up errors. – Robbie Aug 09 '12 at 14:05
  • 1
    @favoretti i actually put the dll into `php/ext` folder. So it should be there. – Mustafa Aug 09 '12 at 15:44
  • @Robbie, it doesnt seem in phpinfo. Yes, i restarted apache many times to make it work after install, didn't work. I guess i intalled 64 bit dll but will check it again. And will check apache logs if there is any now. Then i will write back here. – Mustafa Aug 09 '12 at 15:46
  • @Robbie, checked now, i am using the right dll (just in case i tried two different versions) but it doesn't work. Also couldn't see anything related memcached in apache logs. – Mustafa Aug 09 '12 at 15:54
  • If you create a php file containing just ` phpinfo(); ?>`, do you see your extension loaded? Also, check what extension path does phpinfo() report and see whether your dll is in the right location. – favoretti Aug 09 '12 at 16:01
  • @favoretti, i checked phpinfo and it doesn't load. extension path is `D:\xampp\php\ext` so it is in the right location. However i tried almost 5 different dll files so far. Still didn't load any of them. – Mustafa Aug 09 '12 at 16:08
  • @Mustafa: which windows version do you use? 32 or 64 bit? – favoretti Aug 09 '12 at 16:11
  • 1
    Be careful, **memcache _is not_ memcached**. – Florent Aug 09 '12 at 16:17
  • @favoretti, i'm using Windows 7 64bit. – Mustafa Aug 09 '12 at 16:23
  • @Florent, i noticed the article i followed is titled memcache**D* but it is installing memcache. Right? And which one is better do you think? Am i doing right? – Mustafa Aug 09 '12 at 16:25
  • http://stackoverflow.com/questions/1442411/using-memcache-vs-memcached-with-php – Florent Aug 09 '12 at 16:26
  • My suggestion is go for 32 bit, not 64 bit. You tend to get better support. If you want an all-in-one package, checkout Zend Community Server as opposed to XAMP - it comes with memcache and you just turn it on in the configuration. – Robbie Aug 09 '12 at 23:53
  • Thanks @Robbie but it is not the right time for me to switch between them. I prefer to continue with XAMPP. However if you can lead me about how to go with 32bit from this situation, your help is very welcome. – Mustafa Aug 10 '12 at 01:12
  • 32bit means reinstalling it all anyway... apache and php (mySQL you can leave), so it's no easier. And I'm not saying it would definately work - but you need to rule it out. – Robbie Aug 10 '12 at 04:03
  • Which PHP or XAMPP Version do you have? – René Höhle Aug 11 '12 at 14:39
  • @Stony; PHP Version 5.4.4, Xampp 3.0.12 – Mustafa Aug 11 '12 at 15:46
  • You mean XAMPP 1.8.0? Its the newest XAMPP version which includes PHP 5.4.4. I have the same and can test it. You need the correct .dll file otherwise its not loaded. – René Höhle Aug 11 '12 at 15:47
  • @Stony, yeah 1.8.0 (sorry about 3.0.12 it was on Xampp control panel :) ). I tried several different .dll files to make it work but it didnt load anyway. – Mustafa Aug 11 '12 at 15:49
  • For me, on ubuntu 12.04 linux, this ended up being a matter of needing to restart the php service (sudo service php5-fpm restart). – Kzqai Feb 12 '15 at 20:25

6 Answers6

11

I found the working dll files for PHP 5.4.4

I don't knowhow stable they are but they work for sure. Credits goes to this link.

http://x32.elijst.nl/php_memcache-5.4-nts-vc9-x86.zip

http://x32.elijst.nl/php_memcache-5.4-vc9-x86.zip

It is the 2.2.5.0 version, I noticed after compiling it (for PHP 5.4.4).

Please note that it is not 2.2.6 but works. I also mirrored them in my own FTP. Mirror links:

http://mustafabugra.com/resim/php_memcache-5.4-vc9-x86.zip http://mustafabugra.com/resim/php_memcache-5.4-nts-vc9-x86.zip

Community
  • 1
  • 1
Mustafa
  • 825
  • 3
  • 14
  • 37
7

Add this to your php.ini:

extension="php_memcache.dll"

and restart apache

Edson Medina
  • 9,862
  • 3
  • 40
  • 51
6

Memcached just uses standard text interface so its possible to use it without the module.

// connect
$link = fsockopen($host,$port,$errno,$errst,$timeout);

// set
$data = sprintf("set %s 0 %s %s\r\n%s\r\n",
            $key,$expire,strlen($value),$value);
fwrite($link,$data);
$result = trim(fgets($link));
if ($result == 'ERROR') {
    // :(
}

// get
$data = sprintf("get %s\r\n",$key);
fwrite($link,$data);
$line = rtrim(fgets($link)); 
if ($line != 'END') {
    return rtrim(fgets($link));
}
James Hackett
  • 1,580
  • 2
  • 13
  • 14
5

So i have looked now for a solution. Here you can download some compiled extensions.

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

The problem is that at the moment there is no memcache extension for PHP 5.4. this is the problem why your extension could not be loaded. You need the extension for the correct PHP version and Tead Safe for Windows.

So the easiest way is to work with PHP 5.3 if you need the extension.

The newest version of memcache is the version 3.0.6 but its a beta version you can see it here.

http://pecl.php.net/package/memcache

You could try to take the beta version and compile it with your windows system. But its a lot of work.

René Höhle
  • 26,716
  • 22
  • 73
  • 82
  • So it seems my choices are; downgrading PHP or compiling beta myself with no guarantee. Btw, thank you for pointing that out. Do you know if memcache*D* does have extension for windows and my version? – Mustafa Aug 11 '12 at 18:46
  • The memcache deamon is a standalone programm and should work this is not the problem. The deamon is not connected to the PHP version. And correct this are the choices. Or you can wait until the version is stable and the module is available. – René Höhle Aug 11 '12 at 21:01
0

Also problem can be in loading another version of php module somewhere in apache .conf files. Need to check duplicated "LoadModule php..." directives and if that module compiled to correct version of apache. It seems sound simply, but not when you have several versions of php on one machine :) Or it can be SElinux problem too.

0

xampp windows version is 32bit ,you must be use 32bit memcache.dll

I hole that would be useful for you!

Shaun.lan
  • 71
  • 1
  • 2