I am using PHP with APC cache enabled:
apc.cache_by_default => On
apc.enabled => On
apc.ttl => 7200
Now how can I know if it is using the opcode cache 100%.
For example, let us say that I have this PHP file:
<?php
echo "Hi there";
?>
Now after running this file, let us change it to echo "Bye there";
Shouldn't it echo "Hi there" since the TTL of 7200 seconds is not over yet? Am I right? If so, why does it echo "Bye there"? And if I am wrong how can I force it to use the opcode cache even after changing the file?
I don't think you'll want to do it in production, but you could always use apc_cache_info()
.
function is_file_cached($file) {
$info = apc_cache_info();
foreach ($info['cache_list'] as $cache) {
if ($cache['filename'] == $file) return true;
}
return false;
}
Note that this will iterate over every single file that's cached checking for the specified one, so it's not efficient.
And as far as your specific question, APC will automatically invalidate the cache for a file when it changes. So when you edit the file, APC silently detects this and serves the new file. You can disable this by setting apc.stat = 0
.