Why is file_get_contents faster than memcache_get?

Because file_get_contents mmaps the file and so you'll only have a few file system calls and this will end up in the file system cache. memcache involves out-of-process calls to the memcached (and out of server on a clustered implementation).

The performance of file_get_contents() crucially depends on the type of file system, for example a file on an NFS mounted file system is not mmapped and this access can be a LOT slower. Also on a multi-user server, the file system cache can get rapidly flushed by other processes whereas the memcached cache will almost certainly be in memory.


file_get_contents is the simplest way to retrieve a file. The underlying operating system (especially linux) already has efficient caching mechanisms. Anything else you do just creates overhead and slows things down.

Memcache would make sense if you loaded these files from a remote location.

Edit: It is not necessarily true that file_get_contents is the simplest way. fopen/fget might be even faster - I don't know. But the differences should be minor compared to the complexity of a caching layer.