SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Timing scripts

  1. #1
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,266
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)

    Timing scripts

    My boss has given me a task to create what is essentially a pinging script to run via a web page.

    What he wants is for the app to track:
    • Time from Request to start of processing server-side
    • Time for processing serverside request
    • Time from end of server-side processing to completed page load.
    The server side stuff is easy enough. The client side is what I'm concerned with.

    How can I capture the time of the request (from the time pressing the go button)?
    How can I tell when the page is loaded? Onload fires before the page starts to load, doesn't it?
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How can I capture the time of the request (from the time pressing the go button)?
    You'll have to rely on some of the js Date methods. Perhaps look at the getUTCXxx methods.
    How can I tell when the page is loaded? Onload fires before the page starts to load, doesn't it?
    The onload event fires 'after' the page has loaded.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a guess here - but you might want to timestamp the form submission, possibly like so:

    <form.....onsubmit="timestamp.value=String(new Date.getTime())">
    <input type="hidden" name="timestamp" value="">

    ...which records the time in ms. since 1/1/70 (don't ask). Form.onsubmit is called as soon as the user commences the upload process. Getting the time on the server & doing the math comes next. Unfortunately...the whole process is invalid if the user's system time setting is off. Oh, well...

    Going the other way, you could save the time the server output was complete, and include code to generate an http get when the page load is complete. Something like this might do:
    Code:
    <script type="text/javascript">
    
    onload = function()
    {
    	var oImage = new Image();
    	oImage.src = 'foo.php?timestamp=' + String(new Date.getTime());
    }
    
    </script>
    ...which will pass the load time - again, assuming it's accurate - back to the server, with little overhead. At least that's the theory.

    More....
    ::: certified wild guess :::


Bookmarks

Posting Permissions

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