PDA

View Full Version : Page Loading time


thesavior
03-19-2007, 10:38 PM
What I want to do, is when i start proccessing a page, I have php set a variable with a timestamp or something like that. Then when the page is loaded, at the end, ajax sends php the new timestamp and figures out the difference. Ive never used ajax before, so does anyone have any ideas?

Nightfire
03-19-2007, 10:39 PM
You don't need ajax for this. unless you're wanting to include time for images etc loading?

thesavior
03-19-2007, 10:51 PM
yah, i want to include time for everything, which is why i need the final timestamp to be client side, otherwise i would just intialize a second variable serverside in the footer. I want the full time it takes to load a page. Not creation time.

thesavior
03-20-2007, 11:31 PM
*bump*

goughy000
03-21-2007, 12:53 AM
could be confusing using a timestamp from the server compared with a timestamp from the client as they could possibly be different timezones or one of the clocks set wrong


i think easiest is to start a timer when the page starts loading with javascript and then end the timer with javascript when the page stops loading

then javascript can work out the time taken in seconds

i dont really think this counts as AJAX though

mod:move ?


PS: google finds: http://www.hashemian.com/tools/page-load-time.htm

thesavior
03-21-2007, 01:12 AM
i want to include page creation time though.

iLLin
03-21-2007, 04:50 AM
Why not just set a php variable microtime or w/e, then echo that variable as a javascript variable. Then in the body onload="function to determine time lapse"? Wouldnt that work?

thesavior
03-21-2007, 05:25 AM
i dont think so, because the body onload would run at the beggining of the loading proccess. I would have to add a function call in the footer of my site that does something like that, But the issue is mainly the actual ajax code.

GJay
03-21-2007, 09:48 PM
if this is just for your benefit, then the LORI extension for firefox does what you want: https://addons.mozilla.org/firefox/1743/

otherwise, using a library like prototype it's pretty easy. If that's a problem, then I'd suggest you take the time to figure out what it's doing and pull out the bits you need. Something along the lines of:

add to the beginning of your php script:

//top of script
session_start();
$_SESSION['start'] = microtime(true);
//rest of script


then as javascript:

Event.observe(window,'load',function() {
var url = 'http://www.website.com/timer.php';
var options = {
method: 'get',
onComplete: function(xhr) {
alert(xhr.responseText);
}
};
new Ajax.Request(url,options):
},false);


and timer.php:

session_start();
if(!isset($_SESSION['start'])) {
die("No start time");
}
$end_time = microtime(true);
$time = $end_time - $_SESSION['start'];
unset($_SESSION['start']);
echo $time;


prototype comes from http://www.prototypejs.org

goughy000
03-22-2007, 11:08 PM
someone delete tht spam above this post (post by alpabarot or something)

i think GJay has it! except it dosnt include tht tiny amount of time of transfering tht ajax content to be downloaded

which will be like under a second.. but still :D