memcache vs memcached?

Solution 1:

The short answer: Either one is what you are looking for, but my first choice would be memcache (the first one you listed), purely based on its correct use of nomenclature.

Now here's how I came to that conclusion:

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.

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

Solution 2:

You probably want to see the PHP Client Comparison.

Short version: They will both work, and for most cases either one will do just fine.

Regarding the other issue: Yes, you should be able to do telnet 127.0.0.1 11211. Very few firewalls would block localhost from communicating with itself. If you are not able to connect, verify that memcached really is running by doing ps auxwww | grep memcached, which will also show you the command-line arguments used to start memcached. One of the arguments should be -p 11211 or another port number. See man memcached for the meaning of all the possible arguments.

Solution 3:

As Nate's link suggests, both work perfectly well for simple usage. However, memcached supports more features that allow you to get the most performance out of memcached. The binary protocol reduces the amount of data required to be sent between client and server. Multigets and multisets allow you to get/set multiple items at the same time. If you're finding you need more oomph out of memcache, memcached is the better module. The use of libmemcached suggests that the library itself is possibly more optimised than the PHP only version.

Memcached is a more recent module compared to memcache, having only been released 8 months ago. If you need to target an older version of PHP, then you can only really use memcache.

Solution 4:

The older, buggier one is called php-memcache because that seemed the most appropriate name. The newer, better version independently developed by the folks at Digg was instead named php-memcached in the interest of disambiguation.

People who would recommend you pick one over the other based solely on the correctness of the name really have no business offering technical advice.

Solution 5:

Having used php-memcache recently, I'd have to point you to php-memcached.

Here's a couple of reasons off the top of my head..

1) There's no getErrorCode() or equivalent method, so if get() returns FALSE, you'll have no idea whether that's because the value stored in memcache IS false, or whether there was an issue of some sort.

2) Its hashing algorithm for consistent hashing appears to differ from other implementations, such as the many client libraries built off of libmemcached. This means that if you want to use the same memcache cluster with multiple languages, you will likely have issues where you'll store a value with the PHP client, and other clients won't find it.