Results 1 to 7 of 7

Thread: Retrieve time used to load page

  1. #1
    Join Date
    Mar 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Retrieve time used to load page

    Hi everyone! is there a way you can retrieve the time spent for a page (either HTML, ASPX or PHP) in seconds

    example:
    <script language="Javascript">

    var PageLoadTime;

    PageLoadTime = window.loadingtime;

    document.write("This page took" + PageLoadTime + "sec, to load")

    </script>
    Last edited by lendila; 05-30-2007 at 10:00 AM. Reason: more information

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    <?php $t1 = time().'.'.microtime(); ?>
    YOUR PAGE GOES HERE
    <?php echo (time().'.'.microtime()) - $t1; ?>

    That would give you processing time for the page, for PHP, but not loading time for the user.

    For that, you could echo time() at the start of the script (once the page is requested), then use javascript onLoad in the body tag to check how long it has been.

    there might be a better method.

    It's especially hard, though, to tell from when you actually click a link, unless that link sends the time with it, which could be possible using javaascript, perhaps.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks for help, but I would be more happy if you could help me using plain Javascript.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    That's not going to do anything for you, really.

    1. User requests a page.
    2. Server processes request.
    3. Server prepares page (this is when PHP runs).
    4. Server sends page to user.
    5. User's computer displays page and runs scripts on page (javascript now).

    Javascript would then just tell you how long it took... since it was done.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Mar 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ooh thanks man!!!

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Of course the one exception there is that something on the page might load, so you COULD use javascript to check how long it took for a particular image to load or to check how long it took for a scrolling area on the page to scroll, etc., but all of this is after the page has loaded.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,135
    Thanks
    44
    Thanked 3,231 Times in 3,192 Posts
    Blog Entries
    12

    Default

    The time required by the browser to load the page:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    var begin=new Date().valueOf();
    onload=function(){
    var end=new Date().valueOf();
    alert('This page took '+[end-begin]+' milliseconds to load');
    }
    </script>
    </head>
    <body>
    
    </body>
    </html>
    Notes: Must be the first thing in the head as soon as scripts are allowed there, as shown. Time will only be approximate as it doesn't include loading of meta data or title, etc. But, these usually take very little time.

    Also, this is just the concept. Any particular implementation could, and probably should be a bit different.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •