Bohack

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

PHP Page Stop Watch



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);

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.
Both comments and pings are currently closed.

Comments are closed.

  • Channels

    • Beer (2)
    • Blog (1)
    • Exchange (2)
    • Ham Radio (1)
    • Homebrew (3)
    • Linux / Unix (4)
    • Misc (1)
    • Mods (4)
    • Networking (1)
    • Programming (4)
    • Recipes (2)
    • Scripts (7)
    • Security (1)
    • Software (2)
    • Spam (1)
    • Telco (7)
    • Virtual PC (1)
    • VMware (3)
    • VOIP (3)
    • Windows (16)
    • Windows 2008 (4)
    • Windows 7 (5)
  • Archives

    • September 2012
    • April 2012
    • March 2012
    • February 2012
    • January 2012
    • November 2011
    • September 2011
    • July 2011
    • April 2011
    • February 2011
    • January 2011
    • October 2010
    • August 2010
    • February 2010
    • January 2010
    • December 2009
    • November 2009
    • June 2009
    • May 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
  • Links

    • Blogarama Blogarama – The Blog Directory
    • BlogHub Blog Directory
    • Blogrankings Technology Blogs – Blog Rankings
    • Blogville.us blogville.us
    • Buzzerhut free directory | buzzerhut.com
    • Ontoplist Online Marketing
    • Primechoiceautoparts Discount Auto Parts
    • PTC My Employer
 

  Copyright - Bohack 2025 ©