Symfony-循环引用仅检测到缓存清除的产品

时间:2018-10-24 14:18:20

标签: php symfony

我的cache:clear有点奇怪:在开发环境中没有错误,但是如果我对cache:clear --env = prod进行了操作,则我得到了一个“ 检测到用于服务的循环引用 ”。

怎么了?

stacktrace的副本:

Exception trace:
 () at /var/www/nf-platform/symfony/app/bootstrap.php.cache:2235
 Symfony\Component\DependencyInjection\Container->get() at /var/www/nf-platform/symfony/vendor/symfony/symfony/src/                                             Symfony/Bridge/Doctrine/ManagerRegistry.php:35
 Symfony\Bridge\Doctrine\ManagerRegistry->getService() at /var/www/nf-platform/symfony/vendor/doctrine/common/lib/D                                             octrine/Common/Persistence/AbstractManagerRegistry.php:183
 Doctrine\Common\Persistence\AbstractManagerRegistry->getManager() at /var/www/nf-platform/symfony/vendor/lexik/tra                                             nslation-bundle/Lexik/Bundle/TranslationBundle/Storage/AbstractDoctrineStorage.php:48
 Lexik\Bundle\TranslationBundle\Storage\AbstractDoctrineStorage->getManager() at /var/www/nf-platform/symfony/vendo                                             r/lexik/translation-bundle/Lexik/Bundle/TranslationBundle/Storage/DoctrineORMStorage.php:19
 Lexik\Bundle\TranslationBundle\Storage\DoctrineORMStorage->translationsTablesExist() at /var/www/nf-platform/symfo                                             ny/vendor/lexik/translation-bundle/Lexik/Bundle/TranslationBundle/EventDispatcher/GetDatabaseResourcesListener.php:                                             41
 Lexik\Bundle\TranslationBundle\EventDispatcher\GetDatabaseResourcesListener->onGetDatabaseResources() at n/a:n/a
 call_user_func() at /var/www/nf-platform/symfony/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Even                                             tDispatcher.php:184
 Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() at /var/www/nf-platform/symfony/vendor/symfony/sym                                             fony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:46
 Symfony\Component\EventDispatcher\EventDispatcher->dispatch() at /var/www/nf-platform/symfony/vendor/lexik/transla                                             tion-bundle/Lexik/Bundle/TranslationBundle/Translation/Translator.php:28
 Lexik\Bundle\TranslationBundle\Translation\Translator->addDatabaseResources() at /var/www/nf-platform/symfony/app/                                             cache/pro_/appProdProjectContaine_.php:3871
 appProdProjectContaine_->getLexikTranslation_TranslatorService() at /var/www/nf-platform/symfony/app/bootstrap.php                                             .cache:2261
 Symfony\Component\DependencyInjection\Container->get() at /var/www/nf-platform/symfony/app/cache/pro_/appProdProje                                             ctContaine_.php:7820
 appProdProjectContaine_->getTwigService() at /var/www/nf-platform/symfony/app/bootstrap.php.cache:2261
 Symfony\Component\DependencyInjection\Container->get() at /var/www/nf-platform/symfony/app/cache/pro_/appProdProje                                             ctContaine_.php:3908
 appProdProjectContaine_->getMailManagerService() at /var/www/nf-platform/symfony/app/bootstrap.php.cache:2261
 Symfony\Component\DependencyInjection\Container->get() at /var/www/nf-platform/symfony/app/cache/pro_/appProdProje                                             ctContaine_.php:2025
 appProdProjectContaine_->getFei_DoctrineListener_UserService() at /var/www/nf-platform/symfony/app/bootstrap.php.c                                             ache:2261
 Symfony\Component\DependencyInjection\Container->get() at /var/www/nf-platform/symfony/app/cache/pro_/appProdProje                                             ctContaine_.php:1235
 appProdProjectContaine_->getDoctrine_Dbal_DefaultConnectionService() at /var/www/nf-platform/symfony/app/bootstrap                                             .php.cache:2261
 Symfony\Component\DependencyInjection\Container->get() at /var/www/nf-platform/symfony/app/cache/pro_/appProdProje                                             ctContaine_.php:1349
 appProdProjectContaine_->getDoctrine_Orm_DefaultEntityManagerService() at /var/www/nf-platform/symfony/app/bootstr                                             ap.php.cache:2261
 Symfony\Component\DependencyInjection\Container->get() at /var/www/nf-platform/symfony/vendor/symfony/symfony/src/                                             Symfony/Bridge/Doctrine/ManagerRegistry.php:35
 Symfony\Bridge\Doctrine\ManagerRegistry->getService() at /var/www/nf-platform/symfony/vendor/doctrine/common/lib/D                                             octrine/Common/Persistence/AbstractManagerRegistry.php:231
 Doctrine\Common\Persistence\AbstractManagerRegistry->getManagers() at /var/www/nf-platform/symfony/vendor/symfony/                                             symfony/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php:49
 Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer->warmUp() at /var/www/nf-platform/symfony/vendor/symfony/symf                                             ony/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php:48
 Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp() at /var/www/nf-platform/symfony/app/bootst                                             rap.php.cache:2775
 Symfony\Component\HttpKernel\Kernel->initializeContainer() at /var/www/nf-platform/symfony/app/bootstrap.php.cache                                             :2542
 Symfony\Component\HttpKernel\Kernel->boot() at /var/www/nf-platform/symfony/vendor/symfony/symfony/src/Symfony/Bun                                             dle/FrameworkBundle/Command/CacheClearCommand.php:134
 Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->warmup() at /var/www/nf-platform/symfony/vendor/symfony/                                             symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:96
 Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->execute() at /var/www/nf-platform/symfony/vendor/symfony                                             /symfony/src/Symfony/Component/Console/Command/Command.php:241
 Symfony\Component\Console\Command\Command->run() at /var/www/nf-platform/symfony/vendor/symfony/symfony/src/Symfon                                             y/Component/Console/Application.php:861
 Symfony\Component\Console\Application->doRunCommand() at /var/www/nf-platform/symfony/vendor/symfony/symfony/src/S                                             ymfony/Component/Console/Application.php:193
 Symfony\Component\Console\Application->doRun() at /var/www/nf-platform/symfony/vendor/symfony/symfony/src/Symfony/                                             Bundle/FrameworkBundle/Console/Application.php:84
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/nf-platform/symfony/vendor/symfony/symfony                                             /src/Symfony/Component/Console/Application.php:117
 Symfony\Component\Console\Application->run() at /var/www/nf-platform/symfony/app/console:27

cache:clear [--no-warmup] [--no-optional-warmers] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--                                             ansi] [--no-ansi] [-n|--no-interaction] [-s|--shell] [--process-isolation] [-e|--env ENV] [--no-debug] [--] <comman                                             d>

1 个答案:

答案 0 :(得分:1)

以Symfony的经验,我发现在某些情况下,cache:clear命令是不够的。有时我必须在文件系统级别完全清除缓存。改用以下命令之一(假设您处于类似Unix的环境中)。

对于Symfony 2.x:

rm -rf ./app/cache/*

对于Symfony 3.x和4.x:

rm -rf ./var/cache/*

如果其中有任何.gitkeep个文件,则需要在提交前再次touch个文件。

这样做之后,您无需再运行cache:clear,因为Symfony会在您的第一个应用程序请求上预热全新的缓存。不过,预计您的第一个请求将花费更长的时间。 (根据您的应用程序,可能需要10到20秒。)


关于循环引用,我建议您有两个自定义服务类,它们都已注入Symfony服务容器,然后尝试通过$this->container->get('the_other_service')->whatever();互相引用。

从Symfony 4.0开始,不再支持此功能,从而迫使您改用依赖项注入。 (服务类不应再注入服务容器,因为它看上去很诱人,而且很容易。)-我知道,在从Symfony 2.x或3.x升级时,尤其如此告诉它是最好的。