sybio / apc-bundle

提供命令行任务,用于从控制台操作APC (APCu) 缓存

安装: 61

依赖: 0

建议者: 0

安全: 0

星标: 1

关注者: 8

分支: 0

开放问题: 0

类型:symfony-bundle

1.0.0 2016-12-16 13:06 UTC

This package is auto-updated.

Last update: 2024-09-11 22:17:51 UTC


README

提供命令行来从控制台清除APC/APCu缓存。

APC/APCu的问题在于无法从命令行清除它。因为即使你为PHP CLI启用了APC/APCu,它也与Apache PHP或PHP-CGI APC/APCu实例不同。

这里的技巧是在web目录中创建一个文件,通过HTTP执行它,然后删除它。

安装

  1. 将其添加到您的composer.json文件中

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

    或者

        composer require symbio/apc-bundle:dev-master
        composer update symbio/apc-bundle:dev-master
  2. 将此包添加到您的应用程序内核中

     // app/AppKernel.php
     public function registerBundles()
     {
         return array(
             // ...
             new Symbio\ApcBundle\SymbioApcBundle(),
             // ...
         );
     }
    
  3. 添加网站URL参数

     # app/config/parameters.yml, app/config/parameters.yml.dist
     cache.base_url: https://your.website.url
    
  4. 配置symbio_apc服务

     # app/config/config.yml
     symbio_apc:
         base_url:   %cache.base_url%/
         web_dir:    %kernel.root_dir%/../web
    
  5. 将Apache用户写入权限设置为web_dir

     $ chmod 775 web
    

用法

清除所有APC/APCu缓存

  $ php app/console symbio:apc:clear
  $ php app/console symbio:apcu:clear

Capifony用法

为了在每次capifony部署后自动清除APC/APCu缓存,您可以定义一个自定义任务

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

并添加此钩子

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

Nginx配置

如果您使用nginx并限制传递给fpm的PHP脚本,则需要允许以'APC/APCu'为前缀的PHP文件。否则,您的Web服务器将返回请求的PHP文件作为文本,系统将无法清除APC/APCu缓存。

示例配置

# 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;
    ...