我有基于Symfony2框架的应用程序。我已经转移到生产环境,网站运行正常(我试图调整缓存 - 我的托管是xcache)。但突然间我有这个错误:
致命错误:未捕获的异常 '学说\ COMMON \注释\ AnnotationException'有消息'你 必须启用opcache.save_comments = 1或 zend_optimizerplus.save_comments = 1&#39。在 /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): 教义\共同\注解\ 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 在 /nfsmnt/hosting2_1/6/9/699be0da-dfbd-4651-90de-448d295bb741/playsport.sk/web/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php 在第183行
我无法在我的托管上启用opcache.save_comments(我没有权限,它是临时付费托管服务)。因此,我禁用了prod环境中的所有缓存并尝试重新运行网站。我目前的配置:
网/ 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中的注释缓存或该问题的任何其他解决方案。谢谢!
答案 0 :(得分: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。
答案 1 :(得分:0)
问题解决了!它是由虚拟主机提供商和服务器配置引起的。未正确配置Opcache或Zend Optimizer