cancel
Showing results for 
Search instead for 
Did you mean: 

How to Debugging PHP Infinite loop

How to Debugging PHP Infinite loop

There are situations in Magento 2 when page keeps loading and then you get 500 fatal error, memory limit, or timeout error. 

How to debug this issue ?

1 REPLY 1

Re: How to Debugging PHP Infinite loop

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 $_SERVER['MAGE_PROFILER'] = 'html';

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.

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
         exit();
     }

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

If issue solved, Click Kudos & Accept as Solution.
LitCommerce - The Most Simple & Affordable Multi-channel Selling Tool