问题
I set my project to prod
mode in .env
and everything aside from the custom error pages seem to work.
I have this as my 404 twig template:
{# templates/bundles/TwigBundle/Exception/error404.html.twig #}
{% include 'builder/layout/header.html.twig' with {'title': '404'} %}
<img src="{{ assets('img/not-found.jpeg') }}" class="img-responsive"
id="error-not-found-img" />
<div class="http-error-msg-container">
<h1>404! Page Not Found</h1>
<p>Don't despair, go back to <a href="{{ path('dashboard') }}">Home</a> and try again.</p>
</div>
{% include 'builder/layout/footer.html.twig' %}
and going to a non-existant page (say /dashboard/giorgoirdjfisejf
) returns a blank page. So I added this to my index.php
file:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(-1);
to show the errors and I got this:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /var/www/solomon/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 107
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes) in /var/www/solomon/vendor/symfony/debug/Exception/OutOfMemoryException.php on line 1
I'm not quite sure why this causes an error and unable to debug. var/log/prod.log
doesn't show anything, how do I resolve or better yet, how do I debug?
update
my prod/monolog.yaml file
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
excluded_404s:
# regex: exclude all 404 errors from the logs
- ^/
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine"]
this was auto-generated and I've made no changes
回答1:
Check file permissions on symfony log files. It looks like monolog catches permission denied
exception, tries to write it to log and catches same error again and again.
回答2:
In my case, the error message was almost identical, except the stack trace always pointed to line 171 in StreamHandler.php
. The problem was that Composer was run on Windows and the resulting files were copied to a Linux system. This resulted in the incorrect directory separator being used and Symfony then tried to create /var/www/html/var\log/prod.log
(contains backslash), which obviously fails.
So be sure to run Composer on the same OS on which you will be running the application later.
来源:https://stackoverflow.com/questions/50875215/symfony-4-production-mode-errorhandling-pages-memory-exhausted