Memory limit exceeded in PHP/Laravel error handler

Error handling, investigation and diagnosis is challenging in PHP at the best of times, more so when it isn”t possible to get the error that is occurring.

In this case, Laravel (v8) was attempting to build a nice error page for display, but the error exceeded the page’s ability to deal with the data. This resulted in memory allocation issues, long execution times and a 594 Gateway timeout at Nginx. Additionally, there is no useful information emitted to the app/storage/logs/laravel.log file.

This is the error that is actually happening:

In order to get to the underlying error, it is possible to disable the code that is running out of memory by modifying the /app/app/Logging/CustomizeFormatter.php file and remove the json_encode() call.

Of course, modifying vendor files is not a permanent option so be sure these changes are not committed/persisted!

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.