Memcached vs APC which one should I choose?

PhpCachingMemcachedApc

Php Problem Overview


I read this article: http://www.mysqlperformanceblog.com/2006/09/27/apc-or-memcached/ from way back when.. I want to get the best caching engine available so that my application is really fast. Of course I don't want to over-cache but I want to at least choose the best thing out there. In that article it says Memcached is slow and apc is fast so why is everyone choosing memcached?

http://framework.zend.com/manual/en/zend.cache.backends.html#zend.cache.backends.twolevels here is says "use a fast one (but limited) like Apc, Memcache... and a "slow" one like File, Sqlite..." do you think using Apc as the fast and Memcache as the slow is a good idea?

Php Solutions


Solution 1 - Php

Memcached is a distributed caching system, whereas APC is non-distributed - and mainly an opcode cache.

If (and only if) you have a web application which has to live on different webservers (loadbalancing), you have to use memcache for distributed caching. If not, just stick to APC and its cache.

You should always use an opcode cache, which APC is (also APC will get integrated into php6 iirc, so why not start using it now).

You can/should use both for different purposes.

Solution 2 - Php

Memcached if you need to preserve state across several web servers (if you're load balanced and it's important that what's in the cache is the same for all servers).

APC if you just need access to quick memory to read (& write) on a (or each) server.

Remember APC can also compile and speed up your script execution time. So you could for example be using APC for increased execution performance, while using memcached for cache storage.

Solution 3 - Php

The main advatage of APC is opcode cache. Since PHP 5.5 integrated OpCache to its core and APC for PHP 5.4 is still flagged as beta, it's not official annoucement, but the development of APC would be dropped in near future.

So I would recommend you to choose Memcached.

Solution 4 - Php

I use both one for speed and the other to sync all my servers. If you do use memcache then please do keep in mind of the open ports which you will need to block with iptables.

Solution 5 - Php

Hey Thomaschaaf, I hope this is not tool late for you but please note that APC has some issues related to "user-cache". To make a long story short, when you set time-outs for cache entries, or if your apache crashes inside internal APC code (timeout, for example), then you may suffer some problems.

I have an entry about the issue here: http://nirlevy.blogspot.com/2009/06/apc-futexwait-lockdown-make-your-apache.html, and you should also read http://t3.dotgnu.info/blog/php/user-cache-timebomb.html (from one of the APC developers i think)

Solution 6 - Php

I use only APC since APC is a code cache and acts like memcache ! Only 1 config file instead of 2.

And only 1 place to monitor both cache.....

Solution 7 - Php

It depends on what you are doing but for my drupal websites running on a VPS I find APC works great! If you are running CentOS 6 it is available as a yum update so dead simple to install and no config as the defaults are reasonable. A no brainer imho.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionThomaschaafView Question on Stackoverflow
Solution 1 - PhpKarstenView Answer on Stackoverflow
Solution 2 - Phpxkcd150View Answer on Stackoverflow
Solution 3 - PhpHieu VoView Answer on Stackoverflow
Solution 4 - PhpSaimon LovellView Answer on Stackoverflow
Solution 5 - PhpNir LevyView Answer on Stackoverflow
Solution 6 - PhpThomas DecauxView Answer on Stackoverflow
Solution 7 - PhpfredView Answer on Stackoverflow