ornicar / apc-bundle
1.0.4
2014-11-03 12:21 UTC
Requires
- symfony/framework-bundle: >=2.1,<3.0
This package is not auto-updated.
Last update: 2022-02-01 12:20:49 UTC
README
请使用以下替代方案:https://github.com/Smart-Core/AcceleratorCacheBundle
提供从控制台清除APC缓存的命令行。
APC的问题在于无法从命令行清除它。因为即使你为PHP CLI启用了APC,它也是一个不同于Apache PHP或PHP-CGI APC实例的不同实例。
这里的技巧是在Web目录中创建一个文件,通过HTTP执行它,然后删除它。
先决条件
如果你想要清除Apache部分的APC,你需要在php.ini
中启用allow_url_fopen
来允许打开URL对象文件,或者设置curl选项。
安装
-
将其添加到你的composer.json文件中
{ "require": { "ornicar/apc-bundle": "1.0.*" } }
或者
composer require ornicar/apc-bundle composer update ornicar/apc-bundle
-
将此包添加到你的应用程序内核中
// app/AppKernel.php public function registerBundles() { return array( // ... new Ornicar\ApcBundle\OrnicarApcBundle(), // ... ); }
-
配置
ornicar_apc
服务# app/config/config.yml ornicar_apc: host: http://example.com web_dir: %kernel.root_dir%/../web
-
如果你想要使用curl而不是fopen,请设置以下选项
# app/config/config.yml ornicar_apc: ... mode: curl
使用方法
清除所有APC缓存(opcode+user)
$ php app/console apc:clear
仅清除opcode缓存
$ php app/console apc:clear --opcode
仅清除user缓存
$ php app/console apc:clear --user
清除CLI缓存(opcode+user)
$ php app/console apc:clear --cli
Capifony使用方法
要自动在每次capifony部署后清除APC缓存,你可以定义一个自定义任务
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
并添加以下钩子
# apc after "deploy", "symfony:clear_apc" after "deploy:rollback:cleanup", "symfony:clear_apc"
Nginx配置
如果你正在使用nginx并且限制传递给fpm的PHP脚本,你需要允许以'apc'为前缀的PHP文件。否则,你的Web服务器将返回请求的PHP文件作为文本,系统将无法清除APC缓存。
示例配置
# 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;
...