blakesmoore Posted May 9, 2012 Share Posted May 9, 2012 Hey, I need to generate a script which tells me how long it takes for an external page to load... Please can you help? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/262318-php-page-load-time/ Share on other sites More sharing options...
ManiacDan Posted May 9, 2012 Share Posted May 9, 2012 An external page? $start = microtime(true); file_get_contents('http://www.yourURL.com/page.html'); echo "Page loaded in: " . number_format(microtime(true)-$start,2) . " seconds.<br />"; Quote Link to comment https://forums.phpfreaks.com/topic/262318-php-page-load-time/#findComment-1344328 Share on other sites More sharing options...
blakesmoore Posted May 9, 2012 Author Share Posted May 9, 2012 Thanks for this Dan, will this tell me how long it takes to load any site that i replace 'http://www.yourURL.com/page.html' with? Quote Link to comment https://forums.phpfreaks.com/topic/262318-php-page-load-time/#findComment-1344349 Share on other sites More sharing options...
NLT Posted May 9, 2012 Share Posted May 9, 2012 Thanks for this Dan, will this tell me how long it takes to load any site that i replace 'http://www.yourURL.com/page.html' with? Yes, it should do. You could even add a function you could use with a form rather than editing the PHP file all the time. <?PHP function websitetime($website) { $start = microtime(true); file_get_contents($website); echo "Page loaded in: ". number_format(microtime(true)-$start,2) . " seconds.<br />"; } if(isset($_POST['submit']) && $_POST['website']) { $website = $_POST['website']; websitetime($website); } ?> <form method="post"> Website: <input type="text" name="website" /> <br /> <input type="submit" value="Submit" name="submit" /> </form> Should work, I haven't tested it though. Quote Link to comment https://forums.phpfreaks.com/topic/262318-php-page-load-time/#findComment-1344352 Share on other sites More sharing options...
blakesmoore Posted May 9, 2012 Author Share Posted May 9, 2012 Yeah I already incorperated the form Although, im not sure if it is giving accurate results for loading times? tools.pingdom.com is giving a totally different result? Quote Link to comment https://forums.phpfreaks.com/topic/262318-php-page-load-time/#findComment-1344354 Share on other sites More sharing options...
ManiacDan Posted May 10, 2012 Share Posted May 10, 2012 the pingdom test also fetches external javascript and images. If you want to find the complete load time of a site and all its assets, it will be a significantly longer script. Many sites these days also draw a portion of their interface in javascript, which is even more difficult to time properly. Quote Link to comment https://forums.phpfreaks.com/topic/262318-php-page-load-time/#findComment-1344449 Share on other sites More sharing options...
blakesmoore Posted May 10, 2012 Author Share Posted May 10, 2012 So what is this script measuring? Quote Link to comment https://forums.phpfreaks.com/topic/262318-php-page-load-time/#findComment-1344450 Share on other sites More sharing options...
ManiacDan Posted May 10, 2012 Share Posted May 10, 2012 The 3 line thing I gave you checks exactly what was asked for: The "load time" of an external script. It measures the amount of time it takes for the script to execute and finish giving output. The pingdom test does that, and then parses the output to see if it's HTML. If it is, it fetches images, javascript, and CSS as well, probably in parallel. Quote Link to comment https://forums.phpfreaks.com/topic/262318-php-page-load-time/#findComment-1344461 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.