81
votes

I've pasted the example from php.net for using memcached in php and I'm getting:

Fatal error: Class 'Memcache' not found

I have this in my php.ini:

[memcache]
memcache.hash_strategy = "consistent"
memcache.max_failover_attemps = 100
memcache.allow_failover = 1

Here's info from php -i and php -m respectively:

php -i | grep -i memcache
memcached
memcached support => enabled
libmemcached version => 0.37
Registered save handlers => files user sqlite memcached

php -m | grep -i memcache
memcached

So php seems to have loaded memcached as a module, and php info says that it is loaded and is using v .37. I have not tried yet via apache, I've only been using this through cli right now. Any thoughts?

6
possible duplicate...stackoverflow.com/questions/1171313/…user35288
I just took a look at that and I already have the extension listed in my php.ini and I've already ensured my extension_dir is pointed to the correct place.jpfuentes2
See my answer below for the simple command to install 'MEMCACHE'.Phill Healey
sudo apt-get install php-memcache is what worked for me. packages.ubuntu.com/… shows available packages.Ryan

6 Answers

133
votes

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

23
votes

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.

1
votes

I found solution in this post: https://stackguides.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

0
votes

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.

0
votes

For OSX users:

Run the following command to install Memcached:

brew install memcached
-8
votes

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