Caching in PHP using the filesystem, APC, Memcached and Redis.
If you have some data read from database which you need several time during page creation cache it locally do not depend on any other types of caches.
If you have just one web server or your data set is small so it fits in memory in each of the servers APC Cache may be the most efficient way for you to cache the data.
If local node cache is not large enough to cache good amount of data caching on network by using memcached is very good way to go.
If you need something stored long term or something which needs to be cached but does not fit even in distributed memory you can use file cache (ie on shared storage).
If you do not do any other caching for certain object or if you cache on different level (ie single object constructed from multiple query results) MySQL Query Cache may improve performance of your application.
Same as CPUs have multiple layer of caching and then same data may be stored in OS file cache, than SAN Cache you may implement multiple levels of caching for your application. In different circumstances different layering may make sense. For example you might wish to use APC Cache as L1 cache and File cache as L2 cache if you have large amount of data in long term cache. If you need something like this you might take a look at Eaccelerator which is APC alternative which supports caching user data both on disk and in shared memory. Ref: https://www.percona.com/blog/2006/08/09/cache-performance-comparison/
https://www.digitalocean.com/community/tutorials/how-to-configure-apache-content-caching-on-centos-7 https://www.digitalocean.com/community/tags/caching?type=tutorials
https://developer.joomla.org/joomlacode-archive/issue-33542.html
PHP caching: shm vs. apc vs. memcache vs. mysql vs. file cache (update: fill apc from cron)
Lessons learned:
- shm/apc are 32-60 times faster than memcached or mysql
- shm/apc are 2 times faster than php file cache with apc
- php file cache with apc is 15-24 times faster than memcached or mysql
- mysql is 2 times faster than memcached when storing more than 400 bytes
- memcached is 2 times faster than mysql when storing less than 400 bytes
- php file cache with apc is 2-3 times faster than normal file cache
- php file cache without apc is 8 times slower than normal file cache
Tests were made with PHP 5.3.10, MySQL 5.5.29, memcached 1.4.13, 64bit, 3.4GHz (QEMU): http://we-love-php.blogspot.com/2013/02/php-caching-shm-apc-memcache-mysql-file-cache.html
- Not quite fast ; and concurrent access are not great at all, if several processes try to read/write at the same time
- Local to one server (if you have several servers, you'll have to store the files on each one of them -- NFS being slow)
- But you have a lot of space
- Really fast
- But you have less space
- And it's local to each server too
- quite fast (a bit less than APC ; but still pretty fast)
- Shared between all your servers : each item has to be cached only once, even if you have several webservers.
- You can have several servers in your memcached cluster (which means virtually no limit in the size of the cache) Ref: http://stackoverflow.com/questions/6958475/file-or-apc-cache-engine-in-cakephp