PHP memcached Fatal error: Class 'Memcache' not found
Asked Answered
H

7

91

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?

Hilel answered 17/4, 2010 at 16:8 Comment(6)
possible duplicate...#1171813Compliancy
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.Hilel
See my answer below for the simple command to install 'MEMCACHE'.Calendula
sudo apt-get install php-memcache is what worked for me. packages.ubuntu.com/… shows available packages.Apocrypha
I hve the same problem with php 8.1 and php8.2 right now. It seems like the object-cache.php file is not compatible any more?Jocelyn
I tried to install the module with "d" but failed. I installed Redis now instead, see: unix.stackexchange.com/a/743405/20661Jocelyn
P
151

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.

Pal answered 17/4, 2010 at 16:15 Comment(10)
It is kind of silly, but it's an unfortunately frequent pattern in PHP. Rather than updating the older extension to work with newer things in better ways, but breaking backwards compt, they simply created a new extension. See also mysql and mysqli.Pal
This seems like the right problem. But all the instructions I find seem to say to install memcached, but see memcache. This is a bit confusing.Radbourne
Ok, I found a simple fix (since everything else seemed to not work). Just run this command: sudo aptitude install memcached php5-memcachedRadbourne
Note that those package names will only work on certain specific Debian derivatives. The package names will be different in other environments.Pal
This is ridiculous... thanks for the tip. I have both extensions loaded- would this make any impact on performance?Pickerel
There should be no real performance impact from having both loaded, no.Pal
For the correct way to install 'Memcache' see my answer below.Calendula
memcache (without "d") is not updated for 3 years, so it seems not to work with php8Jocelyn
@Jocelyn -- It does, according to the PECL site for memcache. See also the post below: https://mcmap.net/q/234686/-php-memcached-fatal-error-class-39-memcache-39-not-foundDuhamel
@Duhamel It's been thirteen years and eight days since I wrote this answer, and back then memcache and memcached were both active and maintained. I've added a note about memcache being unmaintained and linked to your post. Thanks for diving in!Pal
C
24

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.

Calendula answered 23/6, 2015 at 18:36 Comment(4)
A couple years later, I think this answer is outdated. sudo apt-get install php-memcache is what worked for me. packages.ubuntu.com/… shows available packages.Apocrypha
@Apocrypha Surely, that only applies if not using PHP5. Plenty of servers still use PHP5 so it's just as valid as it was at the time. Additionally the question is tagged ubuntu-9.10 so this further validates my answer since it relates directly to that version.Calendula
"Memcached & Memcached" ??Stereo
Is there a solution for windows?Grower
D
3

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

Duhamel answered 24/4, 2023 at 15:10 Comment(0)
W
2

I found solution in this post: https://mcmap.net/q/245850/-class-39-memcache-39-not-found-amp-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

Wardroom answered 22/7, 2013 at 2:30 Comment(0)
E
2

For OSX users:

Run the following command to install Memcached:

brew install memcached
Effeminize answered 22/10, 2018 at 1:23 Comment(0)
R
1

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.

Rasure answered 27/12, 2010 at 22:12 Comment(0)
T
-10

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

Throughcomposed answered 10/5, 2015 at 2:15 Comment(1)
All that did was prevent your WordPress install from being able to do any object caching. It's not actually a fix for anything, let alone the question asked by the OP.Calendula

© 2022 - 2024 — McMap. All rights reserved.