我有基於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緩存或該問題的任何其他解決方案。謝謝!
真正的原因是什麼?哪個配置解決了這個問題? – samayo
您必須將zend_optimizerplus.save_comments或opcache.save_comments設置爲true。 –
你可以在php-fpm/conf.d中刪除符號鏈接到opcache(如果你不需要) eg /etc/php/7.0/fpm/conf.d - 刪除@ 10-opcache.ini ... – nvvetal