Class 'Memcache' not found & PHP
Asked Answered
H

6

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

Hampton answered 9/8, 2012 at 12:23 Comment(20)
Do you actually have php_memcache.dll in php extensions folder?Sabinesabino
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.Steffens
@Sabinesabino i actually put the dll into php/ext folder. So it should be there.Hampton
@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.Hampton
@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.Hampton
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.Sabinesabino
@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.Hampton
@Mustafa: which windows version do you use? 32 or 64 bit?Sabinesabino
Be careful, memcache is not memcached.Dibbuk
@favoretti, i'm using Windows 7 64bit.Hampton
@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?Hampton
#1442911Dibbuk
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.Steffens
Thanks @Steffens 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.Hampton
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.Steffens
Which PHP or XAMPP Version do you have?Saleh
@Stony; PHP Version 5.4.4, Xampp 3.0.12Hampton
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.Saleh
@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.Hampton
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).Shaven
H
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

Hampton answered 12/8, 2012 at 8:43 Comment(0)
T
7

Add this to your php.ini:

extension="php_memcache.dll"

and restart apache

Tallyho answered 14/8, 2012 at 9:35 Comment(1)
I upvoted to remove it. Though, your exact "solution" is already in the question.Belligerence
O
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));
}
Ottillia answered 15/8, 2012 at 0:48 Comment(0)
G
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.

Giroux answered 11/8, 2012 at 16:8 Comment(2)
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 memcacheD does have extension for windows and my version?Hampton
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.Saleh
I
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.

Intellectual answered 14/2, 2015 at 9:19 Comment(0)
M
0

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

I hole that would be useful for you!

Maegan answered 10/10, 2016 at 8:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.