Helpful Information
 
 
Category: Ajax and Design
Page Loading time

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?

You don't need ajax for this. unless you're wanting to include time for images etc loading?

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.

*bump*

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

i want to include page creation time though.

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?

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.

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

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










privacy (GDPR)