Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug "Symfony\Component\Debug\Exception\FatalErrorException" errors in PHP (Laravel)?

I am getting reports of many errors encountered by clients

Symfony\Component\Debug\Exception\FatalErrorException

Maximum execution time of 30 seconds exceeded

I, myself, cannot replicate it on my local machine nor on the production server. The URLs for this are all throughout the site, so, I guess it's something global, like a Middleware that's causing this.

I am using Sentry.io to collect the data, but the exception trace only has 1 entry that points to a certain code in the Symfony base code, most commonly:

vendor/symfony/finder/Iterator/ExcludeDirectoryFilterIterator.php at line 73

vendor/symfony/finder/Iterator/DateRangeFilterIterator.php at line 45

vendor/symfony/finder/Iterator/RecursiveDirectoryIterator.php at line 69

Clearly it seems there is something related to the file system, but due to no trace I cannot see where to look for the mistake in the site code. I would guess it is some kind of infinite loop or leak, but there is no trace to look at it, and no consistent way to reproduce the problem.

How should I be looking for the problem and debugging this?

Are there any settings I could set, or tools I could use/enable?

like image 830
Giedrius Avatar asked Aug 09 '18 15:08

Giedrius


Video Answer


2 Answers

Can you register a shutdown function? The shutdown function is called even when a timeout occurs. With it you can print or save the what you want to a log file. I'm not sure if there is a better way to get the backtrace in laravel, but that's how I'd probably do in pure php (calling debug_backtrace).

<?php

function timedOut() {
    //save to a log file instead of printing
    var_dump(debug_backtrace());
}

register_shutdown_function("timedOut");

http://php.net/manual/en/function.register-shutdown-function.php

http://php.net/manual/en/function.debug-backtrace.php

like image 39
Pedro Caseiro Avatar answered Oct 06 '22 18:10

Pedro Caseiro


After reading your chat conversation, I saw that you're using this .env configuration:

CACHE_DRIVER=file 
SESSION_DRIVER=file 

I think this is the problem... I explain myself a little better.

When you use the file driver for the cache or the session, Laravel will create tons of files that stores users session data or application cache data...

If your e-commerce is growing and generating a lot of traffic, then it may be possible that the performance are slowing down because of this tons of files that has to be scanned by the framework.

I think that may be two possible solutions:

  • Your production environment has to be upgraded (I don't know your production server specs or if you have enough resources).
  • The file driver it's becoming too slow for your application requirements.

I usually use redis as cache and session driver, it's faster and with a good strategy for "smart caching" it's a great tool.

I think you should try to use it aswell if possibile. Memcached may be a good solution too.

like image 191
IlGala Avatar answered Oct 06 '22 19:10

IlGala