title: Any reason why Magento 2 index.php file is called several times when visiting a page?
body: <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>And the resulting output in the debug file is (for the search page <a href="https://dev/catalogsearch/result/?q=test" rel="nofollow noreferrer">https://dev/catalogsearch/result/?q=test</a>):</p>
  
  <pre><code>Execution time: 3.8935000896454
  Execution time: 2.0475149154663
  </code></pre>
  
  <p>And it seems it's even called 3 times on the product page (<a href="https://dev/test-product.html" rel="nofollow noreferrer">https://dev/test-product.html</a>):</p>
  
  <pre><code>Execution time: 0.62609481811523
  Execution time: 0.1364049911499
  Execution time: 1.5069890022278
  </code></pre>
  
  <p>Any idea why?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I have tried with various versions of Magento (2.2.x and 2.3) and PHP 7.0 and 7.2 with similar results...</p>