146

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?

Community
  • 1
  • 1
Luca Bernardi
  • 4,191
  • 2
  • 31
  • 39

2 Answers2

162

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.

Mike Starov
  • 7,000
  • 7
  • 36
  • 37
  • 1
    @Mike, Are the limitations still there or **fixed**? – Pacerier Jan 19 '15 at 08:45
  • 32
    @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 ! – Smile Jun 17 '15 at 02:38
  • 3
    @Pacerier people would complain if those limitations were fixed. – Jasen Jan 13 '16 at 02:45
  • 2
    @Jasen Why would people complain if those limitations were fixed? – Gabe Hiemstra Nov 27 '18 at 11:36
  • 2
    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() – Jasen Nov 28 '18 at 03:07
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.

Community
  • 1
  • 1
Mez
  • 24,430
  • 14
  • 71
  • 93
  • 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? –  Oct 17 '12 at 00:42
  • 1
    So the difference between Memcache Vs. Memcached is that they have different authors?? – kta Sep 11 '15 at 07:48
  • 1
    yeah, they have different authors and a different interface. – Jasen Jan 13 '16 at 02:44
  • Big difference is that there is (still) no php memcached module for windows! You can only use php_memcache.dll – CoR Oct 17 '16 at 13:54
  • 1
    Looks like there now is a windows version of memcached: https://commaster.net/content/installing-memcached-windows – Vincent Feb 24 '18 at 00:12
  • 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. – John Jul 21 '18 at 20:34