如何清除Doctrine APC缓存以进行生产?

PMo*_*bed 5 caching apc symfony doctrine-orm apcu

当我向我的一个实体添加一个列并将其发布用于生产时,我有这个问题我必须重新启动Apache才能清除Doctrine元数据APC/APCU缓存.

我已尝试过以下所有命令,但没有一个对我有用:

php -r "apc_clear_cache();"
php -r "apcu_clear_cache();"

sudo php app/console doctrine:cache:clear-metadata
sudo php app/console doctrine:cache:clear-query
sudo php app/console doctrine:cache:clear-result
Run Code Online (Sandbox Code Playgroud)

我收到了--env = prod的错误消息

sudo php app/console doctrine:cache:clear-metadata  --env=prod
sudo php app/console doctrine:cache:clear-query  --env=prod
sudo php app/console doctrine:cache:clear-result --env=prod

 [LogicException]
  Cannot clear APC Cache from Console, its share in the Web server memory and not accessible from the CLI.
Run Code Online (Sandbox Code Playgroud)

我可以让它刷新Doctrine缓存的唯一方法是重启我的apache服务器,这有时可能是一个问题.

我的Symfony项目中Doctine的缓存设置:

doctrine:
    orm:
        metadata_cache_driver: apc
        result_cache_driver: apc
        query_cache_driver: apc
        second_level_cache:
            enabled: true
            log_enabled: false
            region_cache_driver: apc
Run Code Online (Sandbox Code Playgroud)

在每次向生产发布新架构更新时,如何在不重新启动Apache的情况下清除APC缓存.如果负载均衡器后面有许多服务器,情况会更糟.

Tho*_*aux 6

您必须了解在Apache(或Nginx)下运行的Php 与通过命令行运行的Php 不同,它们是2 个无法通信的Linux 进程。

所以,即使你可以通过 CLI 清除缓存,这也不会影响 Apache 下的 php。

apcu_clear_cache在 Symfony 控制器内部调用的最简单方法,或者,您可以通过 CLI 使用 Apache Php 套接字。

我建议使用像http://gordalina.github.io/cachetool/这样的工具,它可以完美地做到这一点。