title: Measure total site loading time in PHP
body: <p>I'm looking for a way to measure each step of a (HTTP) web request in php similar to Firebug's timeline or <a href="http://tools.pingdom.com" rel="nofollow noreferrer">http://tools.pingdom.com</a>. 
  I can use a timer to measure the web requests, but I am looking for some function in PHP that can give me the splits of the total loading time into each section.</p>
  
  <p>For example if I have a textbox that gives URL, I then want to show how long a web page take time to load split by the following: connect time, DNS time, Send and wait and receive time.</p>
  
  <p>I would like to have these statistics to optimize my site. I am looking to code this in PHP.</p>
  
  <p>I have looked at using <code>Microtime()</code> at the start and end of my script with a <code>curl()</code> between the two and then calculate how long it takes to load, but this is the time it takes for PHP to complete the output, not how long it takes to load all the images and CSS. My problem is that that these times are not what tools.pingdom.com or firebug return.</p>
  
  <p>I extract css, images and js tags with DOM. then load them with curl or file_get_content.
  the total time is (start time-end time). but its shows a wrong time!</p>
  
  <p>Also I saw <a href="https://stackoverflow.com/questions/3714909/php-function-for-getting-file-size-and-loading-time-for-a-page">PHP function for getting file size and loading time for a page</a>). It asks as same as my question, but nobody says how can we calculate this time. Is there a function that can help me? </p>