145

Possible Duplicate:
Using Memcache vs Memcached with PHP

Someone can explain me the difference between Memcache and Memcached in PHP environment? What are the advantages of one over the other? Can you also suggest the criteria used to choose between one or the other?

3
  • serverfault.com/questions/63383/memcache-vs-memcached Commented Dec 1, 2009 at 10:21
  • 6
    Doesn't belong on serverfault; this is about the memcache and memcached PHP modules; not the daemon itself. Commented Dec 1, 2009 at 10:28
  • TL;DR use Memecached. Commented May 25, 2023 at 23:11

2 Answers 2

164

They are not identical. Memcache is older but it has some limitations. I was using just fine in my application until I realized you can't store literal FALSE in cache. Value FALSE returned from the cache is the same as FALSE returned when a value is not found in the cache. There is no way to check which is which. Memcached has additional method (among others) Memcached::getResultCode that will tell you whether key was found.

Because of this limitation I switched to storing empty arrays instead of FALSE in cache. I am still using Memcache, but I just wanted to put this info out there for people who are deciding.

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

5 Comments

@Mike, Are the limitations still there or fixed?
@Mike, you explained perfect difference between Memcache and Memcached. They both have very basic difference while storing value. Memcache mostly considers every value as string whereas Memcached stores it value's original type. Thumbs up for your answer !
@Pacerier people would complain if those limitations were fixed.
@Jasen Why would people complain if those limitations were fixed?
because any code that was checking for "FALSE" and now finding FALSE would suddenly not work. PHP is faily good, at maintaining compatibility, it took wordpress to force them to break mail()
122

(PartlyStolen from ServerFault)

I think that both are functionally the same, but they simply have different authors, and the one is simply named more appropriately than the other.


Here is a quick backgrounder in naming conventions (for those unfamiliar), which explains the frustration by the question asker: For many *nix applications, the piece that does the backend work is called a "daemon" (think "service" in Windows-land), while the interface or client application is what you use to control or access the daemon. The daemon is most often named the same as the client, with the letter "d" appended to it. For example "imap" would be a client that connects to the "imapd" daemon.

This naming convention is clearly being adhered to by memcache when you read the introduction to the memcache module (notice the distinction between memcache and memcached in this excerpt):

Memcache module provides handy procedural and object oriented interface to memcached, highly effective caching daemon, which was especially designed to decrease database load in dynamic web applications.

The Memcache module also provides a session handler (memcache).

More information about memcached can be found at » http://www.danga.com/memcached/.

The frustration here is caused by the author of the PHP extension which was badly named memcached, since it shares the same name as the actual daemon called memcached. Notice also that in the introduction to memcached (the php module), it makes mention of libmemcached, which is the shared library (or API) that is used by the module to access the memcached daemon:

memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

This extension uses libmemcached library to provide API for communicating with memcached servers. It also provides a session handler (memcached).

Information about libmemcached can be found at » http://tangent.org/552/libmemcached.html.

6 Comments

It was my understanding that memcacheD has the ability work at the database layer with MySQL commands. That way, your code doesn't have to even call special caching methods. It's all completed in the database?
So the difference between Memcache Vs. Memcached is that they have different authors??
yeah, they have different authors and a different interface.
Looks like there now is a windows version of memcached: commaster.net/content/installing-memcached-windows
Another thing I noticed: "memcached" has a ->quit() function. It is supposed to end the connection. On my linux system it will NOT end it, it will instead have TIME_WAIT and time TCP out after a minute or so.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.