找不到类 'Memcache' 和 PHP


Class 'Memcache' not found & PHP

我通过在Windows7上阅读这篇文章安装了memcached,但不幸的是,我不断收到错误Fatal error: Class 'Memcache' not found in D:'xampp'htdocs'test'memcache'test.php on line 2

第 2 行:$memcache = new Memcache;

Win7 64,Xampp 已安装。我在命令行上使用net start "memcached Server",但它说服务已经开始。

其他一些可能有帮助的信息;

在 php.ini 文件上:

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

更新:phpinfo(); 显示 dll 未加载。到目前为止尝试了几个不同的dll文件,不起作用。dll 的位置也正确。它似乎在正确的文件夹中。

(附言有些人可能认为这个主题可能存在重复,但只有 1 人遵循了相同的说明并在 SO 中出现了相同的错误。这个问题自三月以来没有答案或解决方案。

我找到了 PHP 5.4.4 的工作 dll 文件

我不知道它们有多稳定,但它们肯定有效。积分转到此链接。

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版本,我在编译后注意到(对于PHP5.4.4)。

请注意,它不是 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

把它添加到你的 php.ini:

extension="php_memcache.dll"

并重新启动 Apache

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

所以我现在正在寻找解决方案。在这里你可以下载一些编译的扩展。

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

问题是目前没有 PHP 5.4 的 memcache 扩展。 这就是无法加载扩展的问题。您需要正确的PHP版本和适用于Windows的Tead Safe的扩展。

因此,如果您需要扩展,最简单的方法是使用 PHP 5.3

memcache的最新版本是3.0.6版本,但它是测试版,你可以在这里看到它。

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

您可以尝试使用测试版并使用Windows系统进行编译。但工作量很大。

问题也可能是在apache .conf文件中的某个地方加载另一个版本的php模块。需要检查重复的"加载模块 php..."指令,以及该模块是否编译为正确的 Apache 版本。这听起来很简单,但当你在一台机器上有多个版本的php时,就不行了:)或者它也可能是SElinux问题。

xampp Windows版本是32位,你必须使用32位内存缓存.dll

我猜这对你有用!