У Magento 2 трапляються ситуації, коли сторінка продовжує завантажуватися, а потім виникає фатальна помилка 500, обмеження пам'яті або помилка тайм-ауту. Це нескінченний цикл у коді PHP, коли один і той самий код виконується знову і знову. Це пов'язано з деякими основними проблемами Magento або, найімовірніше, зі стороннім розширенням.
Щоб налагодити нескінченний цикл і знайти вхід у цикл, виконайте наведені нижче дії.
1. Відкрийтеapp/bootstrap.phpфайл і додайте цей код одразу після тегу відкриття PHP <?php у наступному рядку
$_SERVER['MAGE_PROFILER'] = 'html';
2. Відкрийтепостачальник/magento/framework/Profiler.php файл і додайте цей код на початок "публічна статична функція start($timerName, масив $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
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.