Search code examples
phpapc

APC, disk hits, and requires/includes


Pretty simple question, but I can't actually tell for sure. How does PHP behave with requires/includes of files that have been already cached by APC? My understanding is that this cache primarily saves PHP of compiling a file that has been already cached, but it's not clear to me whether it also saves the disk hit necessary to find/fetch the file aswell; so, does it? Or will PHP hit the disk, even if the opcode has been already cached, the only difference being that it doesn't do the compilation process again?

I would like to think requires/includes magically know a file is cached and thus fetch it directly from memory thanks to APC, but I just realized I have no reason to assume this is case, hence why I ask.


Solution

  • APC overrides the function zend_compile_file in the Zend Engine, which among other things is responsible locating and opening the actual files; thanks to this it is able to "hijack" disk hits before they happen if the file is already cached.

    Therefore, yes, files are served from memory if cached.

    Sources: APC Technotes and the Zend Engine source code, specifically zend_language_scanner.c