Bohack

Check In and Tune Out!
 
 
« Exchange 2007 Interop RGC Connector Foo
How to Default Back to Search Companion »

PHP Page Stop Watch

Print This Post Print This Post

Lots of time I have web pages performing complex functions and want to make sure that they execute without a problem. A problem would be they just take too damn long and time out when put under a load. This is the problem when things don’t scale properly, they just get really slow. So in order to gauge how long a page takes to load we really need a stop watch. Luckily we the components of one…


The PHP microtime() function returns the UNIX timestamp with micro-seconds.

<?php echo (microtime()) ?>;   //returns 0.123123 1231231231

The first number is the microseconds from the change of the second number, which is the time in seconds from the UNIX epoch of 0:00:00 Jan 1st 1970. So we can explode the line returned into an array using the explode command, then mathematically add them together. i.e. 1231231231.123123. The last line will take the end time and subtract the start time. The result will be displayed in the HTML comments towards the end of the page, where this code is executed.

Put this at the beginning of your page inside of the php tags.

$start=microtime();
$start=explode(" ",$start);
$start=$start[1]+$start[0];

// do something here

Put this at the end of you page inside of the php tags.

$end=microtime();
$end=explode(" ",$end);
$end=$end[1]+$end[0];

printf("\n<!-- Page was generated by PHP %s in %f seconds -->\n",phpversion(),$end-$start);
Bookmark and Share

Tags: php, Scripts, Web

This entry was posted on Saturday, January 31st, 2009 at 8:20 pm and is filed under Scripts.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

Leave a Reply





  • Author

    • About Bohack
    • Contact Info
  • Channels

    • Blog (1)
    • Exchange (2)
    • Ham Radio (1)
    • Homebrew (2)
    • Linux / Unix (2)
    • Mods (2)
    • Programming (3)
    • Recipes (2)
    • Scripts (5)
    • Spam (1)
    • Telco (3)
    • Virtual PC (1)
    • VMware (2)
    • Windows (11)
  • Archives

    • February 2010
    • January 2010
    • December 2009
    • November 2009
    • June 2009
    • May 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
  • Misc

    • More Links
 

 

Copyright - Bohack 2009i