Php – how to correctly clear php apc cache with capistrano

alternative-php-cachecapistranoPHP

we are using capistrano to deploy our PHP application. and php-apc is enabled on the production server with apc.stat = 0. In capistrano config there is a rule to clear apc cache after deploy:update :

after "deploy:update", "clear_apc_cache"

the cache is successfuly cleared: apc.php 'View Host Stats' shows an uptime of 0 minute, numbers of cached files & hits is close to 0 (not 0 because there is quite a lot of traffic and some files are cached before we can check apc.php)

the problem is, sometime an old file is still cached in apc. I think this is due to an HTTP request starting before capistrano update the 'current' symlink and ending after we clear apc cache. in that case, file included after apc clear in this request are still from the old revision folder (we are using relative path in includes and requires) and are saved in apc cache

Is there a way to permanently fix this? without updating all includes and requires?

for now I will try to delay the "clear_apc_cache" for one or two second but I'm afraid it will cause others problems during the delay (and some requests could still be longer than 2 seconds)

Best Answer

This answer states you need to pass an argument to clear_apc_cache and that only with apc.enable_cli=1 will the APC cache clearing work through CLI calls.

You might want to clear_apc_cache again with the after:restart hook to ensure the previous release is fully cleared.

Related Topic