Skip to content

Latest commit

 

History

History
102 lines (71 loc) · 2.18 KB

README.markdown

File metadata and controls

102 lines (71 loc) · 2.18 KB

Provide a command line to clear APC cache from the console.

The problem with APC is that it's impossible to clear it from command line. Because even if you enable APC for PHP CLI, it's a different instance than, say, your Apache PHP or PHP-CGI APC instance.

The trick here is to create a file in the web dir, execute it through HTTP, then remove it.

Prerequisite

If you want to clear Apache part of APC, you will need to enable allow_url_fopen in php.ini to allow opening of URL object-like files, or set the curl option.

Installation

  1. Add it to your composer.json:

    {
        "require": {
            "ornicar/apc-bundle": "dev-master"
        }
    }

    or:

        composer require ornicar/apc-bundle
        composer update ornicar/apc-bundle
  2. Add this bundle to your application kernel:

     // app/AppKernel.php
     public function registerBundles()
     {
         return array(
             // ...
             new Ornicar\ApcBundle\OrnicarApcBundle(),
             // ...
         );
     }
    
  3. Configure ornicar_apc service:

     # app/config/config.yml
     ornicar_apc:
         host: http://example.com
         web_dir: %kernel.root_dir%/../web
    
  4. If you want to use curl rather than fopen set the following option:

     # app/config/config.yml
     ornicar_apc:
         ...
         mode: curl
    

Usage

Clear all APC cache (opcode+user):

      $ php app/console apc:clear

Clear only opcode cache:

      $ php app/console apc:clear --opcode

Clear only user cache:

      $ php app/console apc:clear --user

Capifony usage

To automatically clear apc cache after each capifony deploy you can define a custom task

namespace :symfony do
  desc "Clear apc cache"
  task :clear_apc do
    capifony_pretty_print "--> Clear apc cache"
    run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} apc:clear --env=#{symfony_env_prod}'"
    capifony_puts_ok
  end
end

and add this hook

# apc
after "deploy", "symfony:clear_apc"