nginx fastcgi返回允许的内存大小耗尽而不是未找到异常
I have a website, written in Symfony2. when users want to access a route which doesn't exists, PHP returns
FastCGI sent in stderr:
PHP message:PHP Fatal error: Allowed memory size of xxx bytes exhausted (tried to allocate 85 bytes)
symfony/symfony/src/Symfony/Component/Debug/Exception/FlattenException. php on line 296
which is in flattenArgs
function: (i think it gets in loop but i don'y know why)
elseif (is_array($value)) {
if ($level > 10) {
$result[$key] = array('array', '*DEEP NESTED ARRAY*');
} else {
$result[$key] = array('array', $this->flattenArgs($value, $level + 1, $count));
}
}
I have increased the memory_limit
value in my php.ini, and also checked my configs. The other sites with same config written in pure PHP are working safe and write.
But naturally it should return 404, not found exception.
so i found the solution!
you shouldn't use security context in error twigs. in my case i was using is_granted
in header, processing some kind of errors is before defining security context.
you can pass it by first checking user object and then security context.
for example {%if app.user and is_granted('IS_AUTHENTICATED_FULLY')%}