Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-19-2007, 09:38 PM   PM User | #1
thesavior
Senior Coder

 
Join Date: Aug 2005
Posts: 1,119
Thanks: 2
Thanked 1 Time in 1 Post
thesavior has a little shameless behaviour in the past
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?
thesavior is offline   Reply With Quote
Old 03-19-2007, 09:39 PM   PM User | #2
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
You don't need ajax for this. unless you're wanting to include time for images etc loading?
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 03-19-2007, 09:51 PM   PM User | #3
thesavior
Senior Coder

 
Join Date: Aug 2005
Posts: 1,119
Thanks: 2
Thanked 1 Time in 1 Post
thesavior has a little shameless behaviour in the past
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 is offline   Reply With Quote
Old 03-20-2007, 10:31 PM   PM User | #4
thesavior
Senior Coder

 
Join Date: Aug 2005
Posts: 1,119
Thanks: 2
Thanked 1 Time in 1 Post
thesavior has a little shameless behaviour in the past
*bump*
thesavior is offline   Reply With Quote
Old 03-20-2007, 11:53 PM   PM User | #5
goughy000
Regular Coder

 
goughy000's Avatar
 
Join Date: Nov 2005
Location: England
Posts: 415
Thanks: 0
Thanked 0 Times in 0 Posts
goughy000 is an unknown quantity at this point
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
__________________
PHP Freelancing!
ByteForums!
Scriptlance.comNeed a job done quick? post it on scriptlance! OR! your a programmer? sign up and get paid for these jobs!

Last edited by goughy000; 03-20-2007 at 11:54 PM.. Reason: used google
goughy000 is offline   Reply With Quote
Old 03-21-2007, 12:12 AM   PM User | #6
thesavior
Senior Coder

 
Join Date: Aug 2005
Posts: 1,119
Thanks: 2
Thanked 1 Time in 1 Post
thesavior has a little shameless behaviour in the past
i want to include page creation time though.
thesavior is offline   Reply With Quote
Old 03-21-2007, 03:50 AM   PM User | #7
iLLin
Regular Coder

 
Join Date: Oct 2005
Location: Right Here
Posts: 654
Thanks: 1
Thanked 0 Times in 0 Posts
iLLin is an unknown quantity at this point
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?
iLLin is offline   Reply With Quote
Old 03-21-2007, 04:25 AM   PM User | #8
thesavior
Senior Coder

 
Join Date: Aug 2005
Posts: 1,119
Thanks: 2
Thanked 1 Time in 1 Post
thesavior has a little shameless behaviour in the past
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.
thesavior is offline   Reply With Quote
Old 03-21-2007, 08:48 PM   PM User | #9
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
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:
PHP Code:
//top of script
session_start();
$_SESSION['start'] = microtime(true);
//rest of script 
then as javascript:
Code:
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:
PHP Code:
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
__________________
My thoughts on some things: http://codemeetsmusic.com
And my scrapbook of cool things: http://gjones.tumblr.com
GJay is offline   Reply With Quote
Old 03-22-2007, 10:08 PM   PM User | #10
goughy000
Regular Coder

 
goughy000's Avatar
 
Join Date: Nov 2005
Location: England
Posts: 415
Thanks: 0
Thanked 0 Times in 0 Posts
goughy000 is an unknown quantity at this point
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
__________________
PHP Freelancing!
ByteForums!
Scriptlance.comNeed a job done quick? post it on scriptlance! OR! your a programmer? sign up and get paid for these jobs!
goughy000 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:38 PM.


Advertisement
Log in to turn off these ads.