Any reason why Magento 2 index.php file is called several times when visiting a page?

时间:2019-03-06 11:30:29

标签: php magento2

I'm trying to figure out why Magento 2 is running slow, and I have disabled XDEBUG with xdebug_disable() and I was trying to mesure execution time when I realized that the index.php script was called several times.

I am using microtime() to mesure execution time of the index.php script, and logging the output to a file, and when visiting the search page, it's printed twice, ex:

define('DEBUG_START', microtime(true)); // At the very top of index.php
...
// content of index.php
...
file_put_contents(DEBUG_FILE, 'Execution time: ' . (microtime(true) - DEBUG_START) . PHP_EOL, FILE_APPEND | LOCK_EX); // At the very end of index.php

And the resulting output in the debug file is (for the search page https://dev/catalogsearch/result/?q=test):

Execution time: 3.8935000896454
Execution time: 2.0475149154663

And it seems it's even called 3 times on the product page (https://dev/test-product.html):

Execution time: 0.62609481811523
Execution time: 0.1364049911499
Execution time: 1.5069890022278

Any idea why?

Update:

I have tried with various versions of Magento (2.2.x and 2.3) and PHP 7.0 and 7.2 with similar results...

1 个答案:

答案 0 :(得分:0)

Ok, after enabling the Dev Tools in chrome I figured the other calls were generated by AJAX calls made by Magento, this became obvious on the checkout page where there were many more...