部署与Capifony Symfony2应用程序 - APC加载器仍然使用以前的版本(Deploying Symfony2 app with Capifony - APC loader still uses previous release)

我最近将Symfony2应用程序升级到2.1并将其迁移到新的服务器,所以我想我会配置Capifony以使部署更简单。 除了它现在不使用APCLoader之外,一切都变得很好,所以我不得不临时对它进行评论,直到它被排序为止。

以下是来自app.php的相关代码:

$loader = require_once __DIR__.'/../app/bootstrap.php.cache'; // Use APC for autoloading to improve performance. // Change 'sf2' to a unique prefix in order to prevent cache key conflicts // with other applications also using APC. $loader = new ApcClassLoader('my_prefix', $loader); $loader->register(true);

问题是'my_prefix'并非每个版本都是唯一的,因此它最终会尝试查找属于以前版本的缓存文件,这些文件可能存在也可能不存在。 这显然是一个非常大的问题!

什么是最好的解决方案? 我应该以某种方式编写capifony将在部署之前运行的任务,将前缀更改为独特的内容,例如#{latest_release}变量? 或者我应该在每次部署后重置APC缓存的全部内容?

我不太确定做这些事情的最好方法,所以如果你推荐其中的一种,请你指出我能够实现它的正确方向吗? 或者有没有我想到的替代解决方案?

I've recently upgraded my Symfony2 application to 2.1 and migrated it to a new server, so I figured I'd configure Capifony to make deploying simpler. Everything has gone great except for the fact that it now doesn't make use of the APCLoader, so I've had to comment this out temporarily until it's sorted.

Here's the relevant code from app.php:

$loader = require_once __DIR__.'/../app/bootstrap.php.cache'; // Use APC for autoloading to improve performance. // Change 'sf2' to a unique prefix in order to prevent cache key conflicts // with other applications also using APC. $loader = new ApcClassLoader('my_prefix', $loader); $loader->register(true);

The problem is that 'my_prefix' isn't unique per release so it'll end up trying to look for cached files that belong to previous releases, which may or may not still be there. This is obviously a very big problem!

What would be the best solution for this? Should I somehow write a task that capifony will run before deploying that changes the prefix to something unique, such as the #{latest_release} variable? Or should I somehow reset the entire contents of the APC cache after each deploy?

I'm not too sure of the best way to do either of these things, so if you'd recommend one of them could you please point me in the right direction to be able to implement it? Or is there an alternative solution that I haven't thought of?

最满意答案

您可以使用ApcBundle ,它提供了一个命令,将在web/目录中创建新文件,通过HTTP执行它,然后将其删除。 然后,您可以在部署脚本中使用run "/path/to/app/console apc:clear"命令。

You could use the ApcBundle, which provides a command that will create new file in the web/ directory, execute it through HTTP, then remove it. Then, you could use your run "/path/to/app/console apc:clear" command in your deployment script.

更多推荐