views:

334

answers:

3

Hey guys,

I'm working on a high-traffic webserver farm serving dynamic PHP code which includes around 100 files on most requests. APC opcode cache is enabled, include_once_override is enabled, and I have allocated 64MB ram to the cache, yet when I strace an apache process I still see it open()ing and stat()ing all of these includes for every request which should be pulled from cache. I can see in cache stats that the cache is being populated and used with a 100% hitrate. Can anyone offer any insight?

+3  A: 

Will, be sure you are using full pathnames to every include in your application. Per the APC documentation:

apc.stat integer

Be careful changing this setting. This defaults to on, forcing APC to stat (check) the script on each request to determine if it has been modified. If it has been modified it will recompile and cache the new version. If this setting is off, APC will not check, which usually means that to force APC to recheck files, the web server will have to be restarted or the cache will have to be manually cleared. Note that FastCGI web server configurations may not clear the cache on restart. On a production server where the script files rarely change, a significant performance boost can be achieved by disabled stats.

For included/required files this option applies as well, but note that for relative path includes (any path that doesn't start with / on Unix) APC has to check in order to uniquely identify the file. If you use absolute path includes APC can skip the stat and use that absolute path as the unique identifier for the file.

A good rule of thumb for PHP is to define a constant that contains the full path to your project like so:

// Assumes __FILE__ is in the root of your project
define('PATH_PROJECT', realpath(dirname(__FILE__)));

then use your includes like so:

include_once PATH_PROJECT . '/some/dir/file.php';

Thus you still have the convenience of relative paths, but are really using full paths.

hobodave
A: 

Thanks! Yes, I did benchmark with and without and saw no noticeable difference.. Now I'm seeing much less stat()s after implementing absolute paths, but, I still see an access() for every file I'm including, even with apc.stat = 0. Is this normal? Why do the files have to be accessed at all?

Will
Are you sure you're not just seeing the initial include of the file? What version are you using? APC has had issues historically with include_once_override. Also, please edit your originial question with responses, instead of using answers.
hobodave
A: 

Sorry for replying to a rather old topic, but I see the same behaviour on my Ubuntu 10.04 server with APC enabled. So I'd also like to know if this is normal.

Hark