3/30/2004 ↓

CODE: Down And Dirty Page Page Timing In PHP

Author: Mark Ghosh Category: Blogging News

Thanks for visiting! We would like to serve you better. Please subscribe to our RSS feed for daily updates. This blog posts regular Wordpress news, updates of themes, plugins, ideas, hacks, quick fixes and everything about blogging, especially about Wordpress. You can also receive updates from this blog via email if you want that method of notification.

There are times when you’re working on a project and you need to test a page’s load
overhead. For instance, if you have a lot of database calls or are using some crazy regex
kung fu. These two little snippets of PHP code will give you a start to finish execution time
of the page you’re loading up. Put the first one at the very top and the second one at the
very bottom and load it up. When the page is finished rendering, just view source and you
can see the execution time in the HTML comment. You can remove the comment if you
want it to echo straight to your page. If you leave it in the comments, you can deploy this
in a production page and monitor the load times whenever you feel like it.

This goes at the top:

<?php
ereg(”(\.[0-9]+) ([0-9]+)”,microtime(),$time);
$starttime = doubleval($time[1])+doubleval($time[2]);
?>

This goes at the end:

<?php
ereg(”(\.[0-9]*) ([0-9]*)”,microtime(),$time);
$endtime=doubleval($time[1])+doubleval($time[2]);
$runtime = number_format($endtime-$starttime,4).” Seconds”;
echo “<!– [$runtime] –>”;
?>

There ya have it! [Jason]

…excerpt from: http://channels.lockergnome.com/web/backissues/20040324.phtml#20040324_2

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Visitors who read this post, also read:

    Friends

    Translate

    Translate to German Translate to Spanish Translate to French Translate to Italian Translate to Portuguese Translate to Japanese Translate to Korean Translate to Russian Translate to Chinese

    Latest Videos

    2 Comments | Leave a comment | Comments RSS

    1. That’s actually a pretty bad way to do it. ereg? Useless. Check out timer_start and timer_stop in WP.

      [Reply] Matt (64 comments.) — 04/1/2004 @ 5:40 pm
    2. Why not get assign the microtime at the start of a script to a temporary variable, then subtract it from the microtime at the end of the script? It’s much cleaner.

      [Reply] Desi Quintans (1 comments.) — 12/6/2005 @ 1:48 am

    Leave a comment

    Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    (required)

    (required, will not be published)


    S2