There are situations in Magento 2 when page keeps loading and then you get 500 fatal error, memory limit, or timeout error. This is an infinite loop in the PHP code, when the same code is executed over and over again. It is related to some core Magento issues or, most likely, third party extension.

To debug an infinite loop and find the loop entrance, please follow the steps below:

1. Open the app/bootstrap.php file and add this code right after PHP open tag <?php in the next line


2. Open the vendor/magento/framework/Profiler.php file and add this code to the beginning of "public static function start($timerName, array $tags = null)" function, e.g.

private static $firsttime = null;
public static function start($timerName, array $tags = null)

    if (!self::$firsttime) {
        self::$firsttime = time();

    if (time() - self::$firsttime > 10) { //10 - is seconds to wait
        \Magento\Framework\Debug::backtrace(false, true, false); // Magento 2 Debug Backtrace

3. Open the page with the loop issue.

4. Check the backtrace information to get an idea of the code creating a loop. Pay attention to the custom extension, you should see their methods over and over again in the backtrace.

5. Once it is done, don't forget to revert changes in bootstrap.php and Profiler.php