2

我有基于 Symfony2 框架的应用程序。我已经转移到生产环境,网站运行良好(我正在尝试调整缓存 - 在我的主机上是 xcache)。但突然我有这个错误:

致命错误:未捕获的异常 'Doctrine\Common\Annotations\AnnotationException' 带有消息“您必须启用 opcache.save_comments=1 或 zend_optimizerplus.save_comments=1。” 在 /nfsmnt/hosting2_1/6/9/699be0da-dfbd-4651-90de-448d295bb741/playsport.sk/web/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:183 堆栈跟踪:#0 /nfsmnt/hosting2_1/6/9/699be0da-dfbd-4651-90de-448d295bb741/playsport.sk/web/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php(162): Doctrine\Common\ Annotations\AnnotationException::optimizerPlusSaveComments()

1 /nfsmnt/hosting2_1/6/9/699be0da-dfbd-4651-90de-448d295bb741/playsport.sk/web/app/cache/prod/appProdProjectContainer.php(237):

Doctrine\Common\Annotations\AnnotationReader->__construct() #2 /nfsmnt/hosting2_1/6/9/699be0da-dfbd-4651-90de-448d295bb741/playsport.sk/web/app/bootstrap.php.cache(2103): appProdProjectContainer->getAnnotationReaderService() #3 /nfsmnt/hosting2_1/6/9/699be0da-dfbd-4651-90de-448d295bb741/playsport.sk/web in /nfsmnt/hosting2_1/6/9/699be0da-dfbd-4651-90de-第 183 行的 448d295bb741/playsport.sk/web/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php

我无法在我的主机上启用 opcache.save_comments(我没有特权,这是临时付费托管服务)。因此,我禁用了 prod 环境中的所有缓存并尝试重新运行网站。我目前的配置:

网络/应用程序.php:

 $loader = require_once __DIR__.'/../app/bootstrap.php.cache';
    
    // Enable APC for autoloading to improve performance.
    // You should change the ApcClassLoader first argument to a unique prefix
    // in order to prevent cache key conflicts with other applications
    // also using APC.
    
    //$apcLoader = new ApcClassLoader(sha1(__FILE__), $loader);
    //$xcacheLoader = new \Symfony\Component\ClassLoader\XcacheClassLoader(sha1(__FILE__) . "PlaySport", $loader);
    //$loader->unregister();
    //$xcacheLoader->register(true);
    
    
    require_once __DIR__.'/../app/AppKernel.php';
    // require_once __DIR__.'/../app/AppCache.php';
    
    $kernel = new AppKernel('prod', false);
    $kernel->loadClassCache();
    //$kernel = new AppCache($kernel);
    
    // When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
    //Request::enableHttpMethodParameterOverride();
    $request = Request::createFromGlobals();
    $response = $kernel->handle($request);
    $response->send();
    $kernel->terminate($request, $response);

config_prod.yml:

    imports:
        - { resource: config.yml }
    
    #framework:
    #    validation:
    #        cache: xcache
    
    #doctrine:
    #    orm:
    #        metadata_cache_driver: xcache
    #        result_cache_driver: xcache
    #        query_cache_driver: xcache
    
    monolog:
        handlers:
            main:
                type:         fingers_crossed
                action_level: error
                handler:      nested
            nested:
                type:  stream
                path:  "%kernel.logs_dir%/%kernel.environment%.log"
                level: debug
            console:
                type:  console

我真的不知道该怎么办。仍然像以前一样出错。如何禁用 Doctrine 中的注释缓存或该问题的任何其他解决方案。谢谢!

4

2 回答 2

1

您可以在您的主机上禁用 Zend OpCache 和/或 Zend Optimizer+ 扩展吗?似乎如果禁用它,您将摆脱此错误,因为 Doctrine 不会对opcache.save_comments参数进行额外检查。

\Doctrine\Common\Annotations\AnnotationReader.php

if (extension_loaded('Zend Optimizer+') && (ini_get('zend_optimizerplus.save_comments') === "0" || ini_get('opcache.save_comments') === "0")) {
  throw AnnotationException::optimizerPlusSaveComments();
}

if (extension_loaded('Zend OPcache') && ini_get('opcache.save_comments') == 0) {
    throw AnnotationException::optimizerPlusSaveComments();
}

禁用任何缓存都不会修复此错误,因为此检查是在AnnotationReader类的构造函数中完成的,它不依赖于任何缓存。

如果不能,您仍然可以尝试使用ini_set PHP 命令将opcache.save_comments参数设置为 1 。

于 2015-05-25T17:25:52.717 回答
0

问题解决了!这是由虚拟主机提供商和服务器配置引起的。Opcache 或 Zend Optimizer 配置不正确

于 2015-05-27T12:38:42.443 回答