Zend - The PHP Company




Miscellaneous

Add Code


Load Timer  

Type: application
Added by: jlemmons
Entered: 11/08/2002
Last modified: 08/12/2001
Rating: - (fewer than 3 votes)
Views: 4380
This code times the build and download of web pages without the need for PERL or JavaScript and has minimal code in this demo, but can be built into a full tilt tracking system.


.. loadtimer.php begins here ..
<?php
# loadtimer.php by Jay@Lemmons.com Aug 2002
#
# This code is called from other pages (see loadtimerdemo.php) and will insert
# build and load time statistics onto the displayed page.
#
# ------------------------------------------------------------------------------
# Mark the current time
# ------------------------------------------------------------------------------
$loadstoptime getmicrotime();
# ------------------------------------------------------------------------------
# Location of graphic
# ------------------------------------------------------------------------------
$graphic_url "/stopwatch_small.gif";
# ------------------------------------------------------------------------------
# Retrieve the time rendering started and rendered
# ------------------------------------------------------------------------------
getUserField("buildstarttime");
getUserField("buildstoptime");
# ------------------------------------------------------------------------------
# Calulate the times and round em off
# ------------------------------------------------------------------------------
$buildet round(($buildstoptime $buildstarttime),2);
$loadet round(($loadstoptime $buildstoptime),2);
$totalet round(($loadstoptime $buildstarttime),2);
# ------------------------------------------------------------------------------
# Build a message and the html code to display it
# ------------------------------------------------------------------------------
$message "This page was built in $buildet seconds and downloaded in $loadet seconds, a total of $totalet seconds";
print 
"<table><tr><td width=100%>&nbsp;</td><td>";
print 
"<a onMouseOver="window.status='$message'; return true;" onMouseOut="window.status=''; return true">";
print 
"<img src="$graphic_url" width="12" height="16" border="0" alt="$message">";
print 
"</a></td></tr></table>";
# ------------------------------------------------------------------------------
# Get variable from GET/POST/COOKIE data
# ------------------------------------------------------------------------------
function getUserField($field_name$default_value "") {    
  return(isset(
$_REQUEST[$field_name]) ? $_REQUEST[$field_name] : $default_value);
# end getUserField();
# ------------------------------------------------------------------------------
# Get current microtime
# ------------------------------------------------------------------------------
function getmicrotime(){ 
    list(
$usec$sec) = explode(" ",microtime()); 
    return ((float)
$usec + (float)$sec); 
    } 
# ------------------------------------------------------------------------------
?>
.. loadtimer.php ends here ..

.. loadtimerdemo.php begins here ..
<title>LoadTimer.php Demo</title>
</head>
<body>
<table><tr><td>
This is a demonstration of LoadTimer.php.<br>
<img src="Http://www.weatherpoint.com/wximages/wciss.gif" width="378" height="242" border="0"><br>
Move your mouse over the stopwatch to see the load statistics!
</td></tr></table>
<?php
# ------------------------------------------------------------------------------
# Benchmark build stop time
# ------------------------------------------------------------------------------
$buildstoptime getmicrotime();
# ------------------------------------------------------------------------------
# Call the loadtimer to display the stopwatch icon and pop up time stats
# ------------------------------------------------------------------------------
print "<iframe src="/loadtimer.php?buildstarttime=$buildstarttime&buildstoptime=$buildstoptime" width=100% height=100% frameborder=0></iframe>";
# ------------------------------------------------------------------------------
?>

</body>
</html>

.. loadtimerdemo.php ends here ..


Usage Example




Rate This Script





Search



This Category All Categories