2017 © Pedro Peláez
 

symfony-bundle accelerator-cache-bundle

Provides a command line task to clear PHP Accelerators cache from the console

image

smart-core/accelerator-cache-bundle

Provides a command line task to clear PHP Accelerators cache from the console

  • Tuesday, November 21, 2017
  • by smart-core
  • Repository
  • 3 Watchers
  • 60 Stars
  • 300,488 Installations
  • PHP
  • 6 Dependents
  • 1 Suggesters
  • 15 Forks
  • 3 Open issues
  • 11 Versions
  • 9 % Grown

The README.md

Provide a command line to clear PHP Accelerator cache from the console., (*1)

The problem with Accelerator cache (like APC, Wincache, Opcache) 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., (*2)

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

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., (*4)

Installation

  1. Add it to your composer.json:
{
    "require": {
        "smart-core/accelerator-cache-bundle": "dev-master"
    }
}
or:
composer require smart-core/accelerator-cache-bundle
composer update smart-core/accelerator-cache-bundle
  1. Add this bundle to your application kernel:
// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new SmartCore\Bundle\AcceleratorCacheBundle\AcceleratorCacheBundle(),
        // ...
    );
}
  1. Configure accelerator_cache service:
# app/config/config.yml
accelerator_cache:
    host: http://example.com
    web_dir: %kernel.project_dir%/web
  1. If you want to use curl rather than fopen set the following option:
# app/config/config.yml
accelerator_cache:
    ...
    mode: curl
#   additional options can be passed to the command
#   curl_opts:
#       CURLOPT_*: custom_value

Usage

Clear all Accelerator cache (opcode+user):, (*5)

$ php app/console cache:accelerator:clear

Clear only opcode cache:, (*6)

$ php app/console cache:accelerator:clear --opcode

Clear only user cache:, (*7)

$ php app/console cache:accelerator:clear --user

Clear the CLI cache (opcode+user):, (*8)

$ php app/console cache:accelerator:clear --cli

Composer usage

To automatically clear accelerator cache after each composer install / composer update, you can add a script handler to your project's composer.json :, (*9)

        "post-install-cmd": [
            "SmartCore\\Bundle\\AcceleratorCacheBundle\\Composer\\ScriptHandler::clearCache"
        ],
        "post-update-cmd": [
            "SmartCore\\Bundle\\AcceleratorCacheBundle\\Composer\\ScriptHandler::clearCache"
        ]

+You can specify command arguments in the extra section:, (*10)

  • --opcode (to clean only opcode cache):
        "extra": {
          "accelerator-cache-opcode": "yes"
        }
  • --user (to clean only user cache):
        "extra": {
          "accelerator-cache-user": "yes"
        }
  • --cli (to only clear cache via the CLI):
        "extra": {
          "accelerator-cache-cli": "yes"
        }
  • --auth (HTTP authentification):
        "extra": {
          "accelerator-cache-auth": "username:password"
        }

Capifony usage

To automatically clear apc cache after each capifony deploy you can define a custom task, (*11)

namespace :symfony do
  desc "Clear accelerator cache"
  task :clear_accelerator_cache do
    capifony_pretty_print "--> Clear accelerator cache"
    run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} cache:accelerator:clear #{console_options}'"
    capifony_puts_ok
  end
end

and add these hooks, (*12)

# clear accelerator cache
after "deploy", "symfony:clear_accelerator_cache"
after "deploy:rollback:cleanup", "symfony:clear_accelerator_cache"

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 accelerator cache., (*13)

Example configuration:, (*14)

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

The Versions

21/11 2017

dev-master

9999999-dev https://github.com/Smart-Core/AcceleratorCacheBundle

Provides a command line task to clear PHP Accelerators cache from the console

  Sources   Download

MIT

The Requires

 

The Development Requires

task apc wincache opcache

21/11 2017
07/11 2015

1.1.0

1.1.0.0 https://github.com/Smart-Core/AcceleratorCacheBundle

Provides a command line task to clear PHP Accelerators cache from the console

  Sources   Download

MIT

The Requires

 

The Development Requires

task apc wincache opcache

21/01 2015

1.0.5

1.0.5.0 https://github.com/Smart-Core/AcceleratorCacheBundle

Provides a command line task to clear PHP Accelerators cache from the console

  Sources   Download

MIT

The Requires

 

task apc wincache opcache

21/01 2015

1.0.6

1.0.6.0 https://github.com/Smart-Core/AcceleratorCacheBundle

Provides a command line task to clear PHP Accelerators cache from the console

  Sources   Download

MIT

The Requires

 

task apc wincache opcache

03/11 2014

1.0.4

1.0.4.0 https://github.com/ornicar/ApcBundle

Provides a command line task to clear APC cache from the console

  Sources   Download

MIT

The Requires

 

task apc

03/11 2014

1.0.3

1.0.3.0 https://github.com/ornicar/ApcBundle

Provides a command line task to clear APC cache from the console

  Sources   Download

MIT

The Requires

 

task apc

05/12 2013

1.0.2

1.0.2.0 https://github.com/ornicar/ApcBundle

Provides a command line task to clear APC cache from the console

  Sources   Download

MIT

The Requires

 

task apc

06/11 2013

1.0.1

1.0.1.0 https://github.com/ornicar/ApcBundle

Provides a command line task to clear APC cache from the console

  Sources   Download

MIT

The Requires

 

task apc

10/06 2013

1.0.0

1.0.0.0 https://github.com/ornicar/ApcBundle

Provides a command line task to clear APC cache from the console

  Sources   Download

MIT

The Requires

 

task apc