95

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
  • 1
    possible duplicate...stackoverflow.com/questions/1171313/… Commented Apr 17, 2010 at 16:10
  • 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. Commented Apr 17, 2010 at 16:26
  • See my answer below for the simple command to install 'MEMCACHE'. Commented Nov 22, 2016 at 11:15
  • 1
    sudo apt-get install php-memcache is what worked for me. packages.ubuntu.com/… shows available packages. Commented Jul 5, 2017 at 21:59
  • 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? Commented Apr 19, 2023 at 9:04

7 Answers 7

153

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.

Sign up to request clarification or add additional context in comments.

10 Comments

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.
Ok, I found a simple fix (since everything else seemed to not work). Just run this command: sudo aptitude install memcached php5-memcached
There should be no real performance impact from having both loaded, no.
@rubo77 -- It does, according to the PECL site for memcache. See also the post below: stackoverflow.com/a/76093380/19980636
@Krokomot 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!
|
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.

4 Comments

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.
@Ryan 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.
"Memcached & Memcached" ??
Is there a solution for windows?
5
+50

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:

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

  • The last Memcached package stable release 3.3.0 from 2024-10-17 depends on PHP>=7.0.0, so can also be used with PHP8.
  • The last Memcache package stable release 8.2 from 2023-04-30 depends on PHP>=8.0.0. For PHP>=7.0 take release 4.0.5.2 from 2019-12-20.

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

Comments

2

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

Comments

2

For OSX users:

Run the following command to install Memcached:

brew install memcached

Comments

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.

Comments

-9

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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.