tags:

views:

271

answers:

2

I have been doing some research on APC Caching with PHP and found that conditional includes just don't work. Like:

if($a) {
    include('a.php');
} else {
    include('b.php');
}

My question is: Can I get around this with variable includes? Such as:

if($a) {
    $file = 'a.php';
} else {
    $file = 'b.php';
}
include($file);

Would the latter code be APC-cached successfully?

A: 

The APC package includes a file, apc.php (it ends up somewhere under /usr/share/doc/, I think, so take a copy), that will show you what files are being cached (you need to edit it and set a password to see full path) - do you know for definite it's not working, or are you going off the chinese-whispers that seem to surround APC?

Greg
+1  A: 

Hi Unknown,

APC will still cache the file, just at a later stage in parsing your app. It's recommended to always include both instead if this is possible.

If you are tied to the conditional includes, you should consider that maybe this is not a big deal at all. :)

Evert