2015-05-25 53 views
1

我有基于Symfony2框架的应用程序。我已经转移到生产环境,网站运行良好(我试图调整缓存 - 我的托管是xcache)。但突然间,我有这样的错误:Symfony2 AnnotationException您必须启用OPCache或ZendOptimizer

Fatal error: Uncaught exception 'Doctrine\Common\Annotations\AnnotationException' with message 'You have to enable opcache.save_comments=1 or zend_optimizerplus.save_comments=1.' in /nfsmnt/hosting2_1/6/9/699be0da-dfbd-4651-90de-448d295bb741/playsport.sk/web/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:183 Stack trace: #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-448d295bb741/playsport.sk/web/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php on line 183

,我不能让我的托管opcache.save_comments(我没有特权,这是偶然的支付托管服务)。因此,我禁用了产品环境中的所有缓存并尝试重新运行网站。我目前的配置:

网/ app.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中的Annotation缓存或该问题的任何其他解决方案。谢谢!

回答

1

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

+0

真正的原因是什么?哪个配置解决了这个问题? – samayo

+0

您必须将zend_optimizerplus.save_comments或opcache.save_comments设置为true。 –

+0

你可以在php-fpm/conf.d中删除符号链接到opcache(如果你不需要) eg /etc/php/7.0/fpm/conf.d - 删除@ 10-opcache.ini ... – nvvetal

1

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

\原则\ COMMON \注解\ 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类的构造函数,这是做不会解决这个错误不依赖任何缓存。

如果你不能,你仍然可以尝试参数设置opcache.save_comments 1与的ini_set PHP命令。

+0

我正在使用websupport.sk托管服务(斯洛伐克最佳提供商)。我无法通过权限更改opcache.save_comments槽.htaccess(我在提问前试过)。我试图要求提供商寻求解决方案,现在我正在等待回应。但有趣的是,该网页运行良好,突然出现错误。 –

+0

也许他们最近改变了他们的配置。你用ini_set()来试试这个技巧吗?如果你不能用.htaccess文件改变它,我不确定这是否会改变任何东西,但你仍应该尝试。 – MeuhMeuh

+0

我试过ini_set(),它似乎是虚拟主机的问题... –

相关问题