Php apc vs memcache

When you are running a site in php (wordpress or non-wordpress), there are two popular options for in-memory cache.

  1. APC (Alternative PHP cache): Opcode and object cache for php.
  2. Memcache: Free & open source, high-performance, distributed memory object caching system.

Note that memcache is not specific to php, but I’m using php as context for this article as php is one of the most popular programming languages and wordpress, php and memcache is a very popular combination.

High level comparions notes between apc and memcache

  1. Opcode cache: apc is opcode cache and caches php bytecodes. So it can lead to faster php execution. Opcode cache is not applicable for memcache as it is out of process in-memory object cache.
  2. Object cache: Both apc and memcache can be used for object cache. Apc being in process cache can be little faster. But Memcache is better if data is large as it be distributed to multiple servers.
  3. Apache restart: Apache restart resets apc cache but it does not reset memcache. This is a good thing as cache warming won’t be needed again. So memcache is better option from this perspective.
  4. Administration: Since memcache is managed by external process, it can be accessed by non php processes also (e.g. python or shell utils like memdump, memccat).

Final comments

Optimum configuration may depend on various factors like traffic, data size etc. But I think in most cases using apc for php opcode cache (not for data) and memcache for data will give a good performance outcome. And moreover with this configuration data cache won’t have to be reloaded with apache restart which may happen whenever you change apache config.

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments