找不到“Memcache”类和 PHP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11883378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Class 'Memcache' not found & PHP
提问by Mustafa
I installed memcached by reading this articleon Windows7 but unfortunately i keep getting error Fatal error: Class 'Memcache' not found in D:\xampp\htdocs\test\memcache\test.php on line 2
我通过在 Windows7 上阅读这篇文章安装了 memcached,但不幸的是我一直收到错误Fatal error: Class 'Memcache' not found in D:\xampp\htdocs\test\memcache\test.php on line 2
Line 2: $memcache = new Memcache;
第 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.
Win7 64,Xampp 安装。我net start "memcached Server"在命令行上使用,但它说服务已经启动。
Some other info which may help;
其他一些可能有帮助的信息;
On php.ini file:
在 php.ini 文件上:
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.
更新:phpinfo(); 显示 dll 未加载。到目前为止尝试了几个不同的dll文件,没有奏效。dll也定位正确。它似乎在正确的文件夹中。
(P.S. Some may think there are possible duplicates about this topic but there is only 1 personwho followed the same instructions and had same error in SO. That question has no answer or solution since march.)
(PS 有些人可能认为这个主题可能有重复,但只有 1 个人遵循相同的说明并在 SO 中出现相同的错误。自 3 月以来,该问题没有答案或解决方案。)
采纳答案by Mustafa
I found the working dll files for PHP 5.4.4
我找到了 PHP 5.4.4 的工作 dll 文件
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).
http://x32.elijst.nl/php_memcache-5.4-nts-vc9-x86.zip
http://x32.elijst.nl/php_memcache-5.4-vc9-x86.zip
它是 2.2.5.0 版本,我在编译后注意到(对于 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:
请注意,它不是 2.2.6 而是有效。我也在我自己的 FTP 中镜像了它们。镜像链接:
http://mustafabugra.com/resim/php_memcache-5.4-vc9-x86.ziphttp://mustafabugra.com/resim/php_memcache-5.4-nts-vc9-x86.zip
http://mustafabugra.com/resim/php_memcache-5.4-vc9-x86.zip http://mustafabugra.com/resim/php_memcache-5.4-nts-vc9-x86.zip
回答by Edson Medina
Add this to your php.ini:
将此添加到您的 php.ini 中:
extension="php_memcache.dll"
and restart apache
并重新启动apache
回答by James Hackett
Memcached just uses standard text interface so its possible to use it without the module.
Memcached 仅使用标准文本界面,因此可以在没有模块的情况下使用它。
// 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));
}
回答by René H?hle
So i have looked now for a solution. Here you can download some compiled extensions.
所以我现在正在寻找解决方案。在这里你可以下载一些编译好的扩展。
http://downloads.php.net/pierre/
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.
问题是目前PHP 5.4没有 memcache 扩展。这就是无法加载您的扩展程序的问题。您需要正确 PHP 版本的扩展程序和适用于 Windows 的 Tead Safe。
So the easiest way is to work with PHP 5.3if you need the extension.
因此,如果您需要扩展,最简单的方法是使用PHP 5.3。
The newest version of memcache is the version 3.0.6but its a beta version you can see it here.
内存缓存的最新版本是3.0.6版,但它是测试版,您可以在此处查看。
http://pecl.php.net/package/memcache
http://pecl.php.net/package/memcache
You could try to take the beta version and compileit with your windows system. But its a lot of work.
您可以尝试使用测试版并使用您的 Windows 系统进行编译。但它的工作量很大。
回答by Ivanov Oleksandr
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.
在 apache .conf 文件中的某处加载另一个版本的 php 模块时也可能出现问题。需要检查重复的“LoadModule php ...”指令,以及该模块是否编译为正确的 apache 版本。这听起来很简单,但当你在一台机器上有多个版本的 php 时就不行了:) 或者它也可能是 SElinux 问题。
回答by Shaun.lan
xampp windows version is 32bit ,you must be use 32bit memcache.dll
xampp windows 版本是 32bit,你必须使用 32bit memcache.dll
I hole that would be useful for you!
我洞那对你有用!

