APC vs. Memcached

In this article I compare APC and Memcached. Two caching methods I studied for a PHP MVC Framework I constructed for a client.

A while ago I was asked to develop a PHP MVC framework from scratch with hooks for caching. After building the MVC framework I decided to take a look at the two preferred caching methods, Memcached and APC, for this particular framework. Below you’ll find some reasons why you should choose the one or the other.

APC

  • APC will be integrated in the upcoming PHP 6.
  • Can also be used to compile and speed up your script execution time.
  • Great performance if the number of reads is greater than 20 for each write and significantly faster than Memcached for 100 reads per write or more, situations.

Memcached

  • Memcached is a distributed caching system which means you’ll be able to use it across multiple servers.
  • Separates the user cache from the opcode cache and helps prevent fragmentation.
  • Can be compiled with optional SASL authentication support for increased security.

Conclusion

If your planning on running a web application across multiple servers and you need your data to be synced across those servers Memcached is the way to go. However, since Memcached’s performance suffers from having to perform writes APC is likely to be the ideal caching method in most situations. APC is really easy to use and since it’ll be integrated in PHP 6 you probably won’t have to update your code when your making the switch to that version. I would like to add that if Apache crashes you’ll most likely run into problems with APC but if your server runs perfectly there is no need to worry.

Author: Luc De Brouwer

Mild-mannered software engineer, Nine Inch Nails lover, gin drinker, cat person, and somewhat of a geek. Ron Swanson is my spirit animal.