Developed with love by KnpLabs Hire us for your project!
117

ApcBundle

by ornicar

UNMAINTAINED - Use https://github.com/Smart-Core/AcceleratorCacheBundle instead

NOT MAINTAINED

Use https://github.com/Smart-Core/AcceleratorCacheBundle instead

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": "1.0.*"
          }
      }
    

    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

Clear the CLI cache (opcode+user):

      $ php app/console apc:clear --cli

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 #{console_options}'"
    capifony_puts_ok
  end
end

and add these hooks

# apc
after "deploy", "symfony:clear_apc"
after "deploy:rollback:cleanup", "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' 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 cache.

Example configuration:
```

Your virtual host

server {
...
location ~ ^/(app|app_dev|apc-.*).php(/|$) { { # This will allow apc (apc-{MD5HASH}.php) files to be processed by fpm
fastcgi_pass 127.0.0.1:9000;
...
```

Copyright (c) 2012 Thibault Duplessis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
ornicar_apc:
host: false
web_dir: ~ # Required
mode: fopen
  • Update README.markdown
    By ornicar, 2 years ago
  • Update README.markdown
    By ornicar, 2 years ago
  • Update README.markdown
    By ornicar, 2 years ago
  • Merge pull request #40 from Nyholm/patch-1
    By shieldo, 2 years ago
  • Using latest_release instead of current_path
    By Nyholm, 2 years ago
  • Merge pull request #37 from giosh94mhz/fix_regression_configuration_interface
    By shieldo, 2 years ago
  • Fix regression introduced by PR #36 (ConfigurationInterface)
    By giosh94mhz, 2 years ago
  • Merge pull request #36 from giosh94mhz/configuration_interface
    By shieldo, 2 years ago
  • Changed configuration to implement ConfigurationInterface
    By giosh94mhz, 2 years ago
  • Merge pull request #33 from tjoelsson/master
    By shieldo, 3 years ago
  • Add support for HTTP basic auth
    By , 3 years ago
  • add `cap deploy:rollback` hook
    By shieldo, 3 years ago
  • Merge pull request #29 from Nyholm/master
    By shieldo, 3 years ago
  • [Bugfix] Hide warnings
    By Nyholm, 3 years ago
  • Merge branch 'master' of https://github.com/digisec/ApcBundle
    By shieldo, 3 years ago
  • Merge pull request #28 from garak/patch-1
    By shieldo, 3 years ago
  • do not enforce dev-master in composer.json
    By garak, 3 years ago
  • update cli section of console command to compatibility with php 5.5
    By shieldo, 4 years ago
  • Merge pull request #26 from evillemez/no-web
    By shieldo, 4 years ago
  • Merge pull request #27 from eymengunay/apcu-support
    By shieldo, 4 years ago
  • [Minor] Typo fixed
    By eymengunay, 4 years ago
  • APCu and OPcache support added
    By eymengunay, 4 years ago
  • added --cli option to apc:clear command
    By evillemez, 4 years ago
  • corrected method call
    By shieldo, 4 years ago
  • Merge pull request #22 from eymengunay/router-request-context
    By shieldo, 4 years ago
  • added branch alias master => 1.1.x
    By shieldo, 4 years ago
  • [Minor] Nginx configuration example fixed
    By eymengunay, 4 years ago
  • Symfony 2.0 support dropped. Request context configuration is only available in Symfony 2.1+
    By eymengunay, 4 years ago
  • Example nginx server configuration added
    By eymengunay, 4 years ago
  • Host configuration fallback to router context
    By eymengunay, 4 years ago