SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Thread: Creation time

  1. #1
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creation time

    On the bottom of polkaudio.com's website it gives you the time in seconds it took to create the website, I thought this was pretty cool and was wondering how to re-create the effect.

  2. #2
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it show the creation time thru a function in php... the site's done using php and the creation time is probably the execution/parsing time of the php script used to created the html file you see...

    phpBB forums have this feature built in... check this out: http://phpbb.sourceforge.net/phpBB/ scroll right to the bottom and you'll see a message like
    "phpBB Created this page in 0.141029 seconds."

    as to how to implement it, i'll leave it to the experts...

  3. #3
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know it was created with php and I knew phpbb had it as well, what I'm wondering is if the time is a global variable or something, or did they run a function that acutally timed the creation of the page, and then spat out a number. i.e. does php keep track of page creation times or did they makeup a function.

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2000
    Location
    Yeppoon, Australia
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The examples and information for the PHP microtime() function (at http://www.php.net/manual/en/function.microtime.php) give you all that you need to do this.

    Basically you grab a timestamp at the very start of the page, do the processing, grab another timestamp and the difference between the two (nicely formatted) is the page generation time. There are code examples there.
    Knowledge is knowing that a tomatoe is a fruit; wisdom is not putting it in a fruit salad.

  5. #5
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $mtime microtime();
    $mtime explode(" ",$mtime);
    $mtime $mtime[1] + $mtime[0];
    $endtime $mtime;
    $totaltime = ($endtime $starttime);
    printf("<center><font size=-2>phpBB Created this page in %f seconds.</font></center>"$totaltime); 
    that's the code using microtime()

  6. #6
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey cool! I knew it had to be a php function.

  7. #7
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How would I do this over the course of an entire page?

    Originally posted by redemption
    PHP Code:
    $mtime microtime();
    $mtime explode(" ",$mtime);
    $mtime $mtime[1] + $mtime[0];
    $endtime $mtime;
    $totaltime = ($endtime $starttime);
    printf("<center><font size=-2>phpBB Created this page in %f seconds.</font></center>"$totaltime); 
    that's the code using microtime()
    PHP Code:
    $mtime microtime();
    //Put all of my page code in here
    dbconnect()
    laksjdfl
    laskdjf
    $mtime 
    explode(" ",$mtime);
    $mtime $mtime[1] + $mtime[0];
    $endtime $mtime;
    $totaltime = ($endtime $starttime);
    printf("<center><font size=-2>phpBB Created this page in %f seconds.</font></center>"$totaltime); 
    like dat? and why was the mtime array exploded? And where did the variable $starttime come from? Idon'tsee it defined anywhere before that.

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hers how I do it.

    PHP Code:
    <?
    //At top of script
    $stime microtime();

    //Body
    for($i=0;$i<10;$i++) {
        print 
    "$i";
        }
    print 
    "<br>";


    //At bottom of script
    $etime microtime();
    $stime explode(" "$stime);
    $etime explode(" "$etime);
    $stime $stime[0] + $stime[1];
    $etime $etime[0] + $etime[1];
    print 
    $etime $stime;
    ?>

    The reason for the addition is microtime rerturns a string with the microseconds a space then the regualr seconds. So you need to add the two toegther then subtract the number from the start and from the end.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey cool thanks, btw, when do you become a mentor

  10. #10
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any idea on how to incorporate this into vbulletin's templates? I don't get this ob_get_contents() thing.

  11. #11
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Snoozy
    hey cool thanks, btw, when do you become a mentor
    The mentors are the "Moderators" of Sitepoint.
    I guess Wayne or one of the other admins has to make you a mentor.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  12. #12
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Defender1
    I guess Wayne or one of the other admins has to make you a mentor.
    Yep, you have to be choosen by existing mentors/advisors

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature


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
  •