jpfuentes2
jpfuentes2

Reputation: 2135

PHP memcached Fatal error: Class 'Memcache' not found

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?

Upvotes: 92

Views: 217503

Answers (7)

Krokomot
Krokomot

Reputation: 5803

To avoid confusion as this is an older question, a small prologue:

rubo77 refreshed this question by placing a bounty and asking for a canonical answer. Reading the little bit old but nevertheless still valid answers -- see esp. the accepted one -- , I realized that indeed some basic but important, so to say canonical, links miss.

So here shall be provided not a canonical answer as such -- which could change in details over the years -- but canonical links which will provide the answer.


The Missing Link

Sorry for the fossil joke ^^. Ok, back to serious. The main canonical source to answer the question is of course php.net, and more precisely:

The extensive and up-to-date ServerPilot installation guide for Memcached as well as Memcache is also pretty useful.

Naturally, the question comes up -- What about PHP8? Lets take a look into the respective repository, the PHP Extension Community Library (PECL), and we find:

  • The last Memcache package stable release 8.0 from 2020-12-06 depends on PHP>=8.0.0. For PHP>=7.0 take release 4.0.5.2 from 2019-12-20.
  • The last Memcached package stable release 3.2.0 from 2022-03-24 depends on PHP>=7.0.0, so can also be used with PHP8.

Note, that Memcache (without 'd') is no longer maintained.


So these sources should be the very first places to look for (after Stackoverflow, of course), before starting a deeper web search campaign (which won't yield that much more, tbh).

Upvotes: 3

Charles
Charles

Reputation: 51411

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


In the ~13 years since this answer was written, much has changed in the PHP community. The old memcache extension seems to be unmaintained, so please use the memcached extension instead if you can. It's a better option regardless! See this other answer below for up to date installation and build links.

Upvotes: 152

Phill Healey
Phill Healey

Reputation: 3180

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.

Upvotes: 24

Maihan Nijat
Maihan Nijat

Reputation: 9344

For OSX users:

Run the following command to install Memcached:

brew install memcached

Upvotes: 2

neofetter
neofetter

Reputation: 3022

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

Upvotes: -10

Xman Classical
Xman Classical

Reputation: 5406

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

Upvotes: 2

Dalius Šidlauskas
Dalius Šidlauskas

Reputation: 183

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.

Upvotes: 1

Related Questions