Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    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?

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You don't need ajax for this. unless you're wanting to include time for images etc loading?

  • #3
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    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.

  • #4
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    *bump*

  • #5
    Regular Coder goughy000's Avatar
    Join Date
    Nov 2005
    Location
    England
    Posts
    415
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Last edited by goughy000; 03-20-2007 at 11:54 PM. Reason: used google
    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!

  • #6
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    i want to include page creation time though.

  • #7
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #8
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    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.

  • #9
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    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

  • #10
    Regular Coder goughy000's Avatar
    Join Date
    Nov 2005
    Location
    England
    Posts
    415
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •