Page Load Speed: microtime() is much faster than Google Developer Tools


#1

Greetings,

I’m trying to speed up the load time on my site. Google Developer Tools says my main HTML/TEXT page takes 2.18 seconds to load (Waiting TTFB). I assume this has something to do with inefficient PHP/MySQL scripts.

However, I use the following code to see how long the script loads:

[php]<?php
$start_time = microtime(true); // very first line

echo “This page was generated in “.(microtime(true) - $start_time).” seconds.”; // very last line
?>[/php]
Apparently this results in a page loading time of 0.38 seconds.

Although this is wrong because the page really does load up in 2-3 seconds as Google Developer Tools indicated.

Can anyone explain this behavior? Any tips on speeding this up?

Thanks
Kind regards


#2

You’re measuring the amount of time between 2 PHP statements, which has nothing to do with the amount of time between a page request and the page being fully loaded.


#3

I’m using this to measure the time through the entire PHP script. On Google Developer Tools, the page has the following time for the loading of my homepage (just the html/txt page - without the images or anything else loading):

Stalled: 2.000 ms
DNS Lookup: 0
Initial Connection: 61.000 ms
Request Sent: 0
Waiting (TTFB): 2.18 s
Content Download: 20.000 ms

I don’t understand why TTFB is 2.18 seconds if PHP says the script finishes in 0.38 seconds. I’m assuming my PHP script and MySQL queries are running quickly then…

Is this a network issue or a Dreamhost issue? Is this something I can fix?

The reason this is a problem is because some visitors are complaining about the site lagging and getting too slow at various times. It’s inconsistent, sometimes the site is slow and other times is nice and fast.


#4

It’s the network. You can’t fix this :frowning: