У Magento 2 виникають ситуації, коли сторінка довго завантажєуться, і тоді ви отримуєте 500 фатальну помилку, обмеження пам’яті або помилку очікування (timeout error). Це називається нескінченним циклом (infinite loop) в PHP-коді, коли той самий код виконується знову і знову. Це пов’язано з основними проблемами Magento або, швидше за все, третьостороннім розширенням .
Щоб виправити нескінченний цикл (infinite loop) і знайти вхід у цикл, виконайте наведені нижче дії:
1. Відкрийте файл app/bootstrap.php та додайте наступний код у наступному після відкриваючого PHP тегу <?php рядку:
$_SERVER['MAGE_PROFILER'] = 'html';
2. Відкрийте файл vendor/magento/framework/Profiler.php та додайте наступний код на початок функції "public static function start($timerName, array $tags = null)" , напр.
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
exit();
}
3. Відкрийте сторінку з проблемою нескінченного циклу.
4. Перевірте інформацію бектрейсу, щоб отримати уявлення про те, який код створює цикл. Зверніть увагу на кастомне розширення, ви повинні побачити його методи знову і знову в бектрейсі.
5. Після цього не забудьте скасувати зміни в bootstrap.php та Profiler.php
My sympathies with your country, we are waiting for this unjust war to end.
I'm 4 days almost 14 hours a day trying to find just this subject. I almost cried with joy when I saw him... everything was going well in item 1. kkk
Then in item 2, everything went wrong... I couldn't understand how to do it right, and in many ways I change the error on line 300... which is Stop.
I'm a layman, I'm not a developer... but I'm a comparator and I get by.
Would it be too much to ask to detail just a little more how to do item 2?
Thank you in advance
Jean Carlos
In the backtrace you will see repeat methods execution or a group of methods. Then in one of that methods to stop the loop you need to do something like this:
self::isSomeFunctionExecutingNow = false;
public function someFunctionName($params)
{
if (self::isSomeFunctionExecutingNow) {
return $something;
}
self::isSomeFunctionExecutingNow = true;
//function code here, that creates a loop
self::isSomeFunctionExecutingNow = false;
return $something;
}
This is just a quick solution, a better solution needs to understand the code.