Provide a command line to clear APC/APCu cache from the console., (*1)
The problem with APC/APCu is that it's impossible to clear it from command line.
Because even if you enable APC/APCu for PHP CLI, it's a different instance than,
say, your Apache PHP or PHP-CGI APC/APCu instance., (*2)
The trick here is to create a file in the web dir, execute it through HTTP,
then remove it., (*3)
Installation
-
Add it to your composer.json:, (*4)
json
{
"require": {
"symbio/apc-bundle": "dev-master"
}
}
, (*5)
or:, (*6)
sh
composer require symbio/apc-bundle:dev-master
composer update symbio/apc-bundle:dev-master
, (*7)
-
Add this bundle to your application kernel:, (*8)
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new Symbio\ApcBundle\SymbioApcBundle(),
// ...
);
}
-
Add parameter with website URL:, (*9)
# app/config/parameters.yml, app/config/parameters.yml.dist
cache.base_url: https://your.website.url
-
Configure symbio_apc
service:, (*10)
# app/config/config.yml
symbio_apc:
base_url: %cache.base_url%/
web_dir: %kernel.root_dir%/../web
-
Set Apache user write permissions to web_dir, (*11)
$ chmod 775 web
Usage
Clear all APC/APCu cache:, (*12)
$ php app/console symbio:apc:clear
$ php app/console symbio:apcu:clear
Capifony usage
To automatically clear APC/APCu cache after each capifony deploy you can define a custom task, (*13)
namespace :symfony do
desc "Clear APC/APCu cache"
task :clear_apc do
capifony_pretty_print "--> Clear APC cache"
run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} symbio:apc:clear --env=#{symfony_env_prod}'"
capifony_puts_ok
end
end
and add this hook, (*14)
# apc
after "deploy", "symfony:clear_apc"
Nginx configuration
If you are using nginx and limiting PHP scripts that you are passing to fpm you need to allow 'APC/APCu' prefixed php files. Otherwise your web server will return the requested PHP file as text and the system won't be able to clear the APC/APCu cache., (*15)
Example configuration:, (*16)
# Your virtual host
server {
...
location ~ ^/(app|app_dev|apcu?-.*)\.php(/|$) { { # This will allow APC/APCu (apc-{MD5HASH}.php) files to be processed by fpm
fastcgi_pass 127.0.0.1:9000;
...