Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Do APC and Memcached cache the same data? I understand that APC caches both files and objects/variables whereas memcached is object-only, but does memcached offer anything that APC doesn't?

I've seen setups where both are used, but that seems to be a waste of RAM unless I'm missing something?

TIA, JD

share|improve this question

1 Answer 1

up vote 3 down vote accepted

On a single server, there's not much point caching the same data in both places. That will use twice the RAM for no real advantage. In this case, it's probably easiest to use APC, because it's one less process to run, and one less interface to learn.

Memcache becomes more useful when you have a whole cluster of servers. Memcache can be queried by multiple servers (and also by multiple processes on the same server). In contrast, data in the APC cache can only be used by PHP on its own server. This makes Memcache more efficient, because you can cache data once and use it on the whole cluster. Memcache itself also can be clustered, so that you can pool the RAM from a bunch of different machines, and use them all as one big cache.

My company uses both Memcache and APC simultaneously. We have a dozen servers running Memcache; these servers cache complex data structures so that we don't have to make database queries all the time. We also use APC to store a little bit of info that's used all the time, like configuration settings. Without APC, we were inundating our Memcache servers with tons of requests for simple data like "Is the app in read-only mode?" Our Memcache servers could handle it, but it's obviously more efficient to keep that information around in local memory.

share|improve this answer
    
Great answer with real-world info, thanks Ryan –  Jonathan Day Feb 14 '11 at 21:10
1  
Also, APC caches the actual PHP code that is executing. This is a major bonus as it means the code doesn't have to be "recompiled" for each request. –  devicenull Feb 15 '11 at 14:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.