Class 'Memcache' not found & PHP

一笑奈何 提交于 2019-11-27 03:09:49

问题


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


回答1:


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




回答2:


Add this to your php.ini:

extension="php_memcache.dll"

and restart apache




回答3:


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));
}



回答4:


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.




回答5:


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.




回答6:


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

I hole that would be useful for you!



来源:https://stackoverflow.com/questions/11883378/class-memcache-not-found-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!