2015-05-25 93 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(),它似乎是虛擬主機的問題... –

相關問題