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

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.


If you are not sure about the reason of the exception then you can handle it in two ways

1 increase request timeout ini_set('max_execution_time', 60); //60 seconds = 1 minute

2 wrap your code in try catch

try{
  //logic goes here
}catch(\Excaption $e){
 Log::error($e->getMessage().' '. $e->getFile().' '. $e->getLine());
 return back()->with('error',$e->getMessage() );
}

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