PHP memcached 致命错误: 未找到“ Memcache”类

我粘贴了来自 Php.net的在 php 中使用 memcached 的示例,我得到了:

Fatal error: Class 'Memcache' not found

我的 php.ini 里有这个:

[ memcache ]
Hash _ 娱乐策略 = “一致的”
Max _ falover _ attemps = 100
Allow _ falover = 1

下面是分别来自 php-i 和 php-m 的信息:

Php-i | grep-i memcache
Memcached
Memcached 支持 = > 启用
Libmemcached version = > 0.37
已注册的保存处理程序 = > files user sqlite memcached

Php-m | grep-i memcache
Memcached

所以 php 似乎已经加载了 memcached 作为一个模块,而 php info 说已经加载了 memcached 并且正在使用 v.37。我还没有尝试通过 apache,我现在只通过 cli 使用这个。有什么想法吗?

195319 次浏览

There are two extensions for memcached in PHP, "memcache" and "memcached".

It looks like you're trying to use one ("memcache"), but the other is installed ("memcached").

The right is php_memcache.dll. In my case i was using lib compiled with vc9 instead of vc6 compiler. In apatche error logs i got something like:

PHP Startup: sqlanywhere: Unable to initialize module Module compiled with build ID=API20090626, TS,VC9 PHP compiled with build ID=API20090626, TS,VC6 These options need to match

Check if you have same log and try downloading different dll that are compiled with different compiler.

I found solution in this post: https://stackoverflow.com/questions/11883378/class-memcache-not-found-php#=

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

I went into wp-config/ and deleted the object-cache.php and advanced-cache.php and it worked fine for me.

Dispite what the accepted answer says in the comments, the correct way to install 'Memcache' is:

sudo apt-get install php5-memcache

NOTE Memcache & Memcached are two distinct although related pieces of software, that are often confused.

EDIT As this is now an old post I thought it worth mentioning that you should replace php5 with your php version number.

For OSX users:

Run the following command to install Memcached:

brew install memcached