JsusSalv Posted November 16, 2008 Share Posted November 16, 2008 Hello Everyone: I'm trying to add a page load time script to my pages and would like some opinions from the community. Which script would work best for this purpose: [b]1):[/b] <?php // Place at very bottom of page. echo ($load = round(microtime(), 5)).'s'; ?> 2) <?php // Insert this block of code at the very top of page. $time = microtime(); $time = explode(" ", $time); $time = $time[1] + $time[0]; $start = $time; ?> <?php // Place this part at the very bottom of page. $time = microtime(); $time = explode(" ", $time); $time = $time[1] + $time[0]; $finish = $time; $totaltime = ($finish - $start); printf ("This page took %f seconds to load.", $totaltime); ?> I've tested both code blocks on the same page and on separate pages but they produce different results. I'm also using the Firefox add-on, YSlow, for testing purposes and it too produces a VERY different result. I've also gone to the following websites and again, different results: 1) http://www.websiteoptimization.com/services/analyze/ 2) http://tools.pingdom.com/ However, both websites did produce almost identical load times. Would be nice to know what they're using. Can I get some feedback on which code would be best to use on my pages and whether I should be concerned with YSlow's result? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/132916-solved-page-load-time-which-is-faster-and-more-importantlyprecise/ Share on other sites More sharing options...
laffin Posted November 16, 2008 Share Posted November 16, 2008 if yer using php5, ya can use microtime(1) or microttime(true) this way microtime returns a float value already, so unecessary to do the explode trick to convert to a float. <?php $starttime=microtime(true); . . . echo "Page load time: ". round(microtime(true)-$startime,5); The first script excertpt ya posted just returns a unix timestamp, which is useless in a display unless ya do something with it. second one is what ya use to display the load time of a page, but note the above tip Quote Link to comment https://forums.phpfreaks.com/topic/132916-solved-page-load-time-which-is-faster-and-more-importantlyprecise/#findComment-691168 Share on other sites More sharing options...
JsusSalv Posted November 16, 2008 Author Share Posted November 16, 2008 Thanks, I went with that code as other codes on the web followed the same route. However, I'd still like to know why the YSlow Firefox add-on shows something different. Quote Link to comment https://forums.phpfreaks.com/topic/132916-solved-page-load-time-which-is-faster-and-more-importantlyprecise/#findComment-691187 Share on other sites More sharing options...
laffin Posted November 16, 2008 Share Posted November 16, 2008 U shud consider that image links arent embedded into a page, they are loaded. so any web browser tool that shows page loadig times is probably gonna include the image loading as well. which shud be slower than what yer functions display/ Quote Link to comment https://forums.phpfreaks.com/topic/132916-solved-page-load-time-which-is-faster-and-more-importantlyprecise/#findComment-691223 Share on other sites More sharing options...
JsusSalv Posted November 16, 2008 Author Share Posted November 16, 2008 Brilliant! Thanks, that makes great sense. That pretty much solves the mystery here. Rock on! Quote Link to comment https://forums.phpfreaks.com/topic/132916-solved-page-load-time-which-is-faster-and-more-importantlyprecise/#findComment-691226 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.