Zend - The PHP Company




Date & Time

Add Code


Dealing with microtime  

Type: code fragment
Added by: mgkimsal
Entered: 12/05/2000
Last modified: 08/12/1999
Rating: **** (8 votes)
Views: 7165
This is a quick function I wrote to parse out the 'microtime()' feature, and deal with the results mathmatically. Since microtime() returns the milliseconds, then a space, then the unix timestamp, using the results from microtime() itself weren't conducive to quick math. We had some pages here that we needed to time down to the millisecond, so we used this. :)


<?
function getmicrotime() {
$temparray=split(" ",microtime());
$returntime=$temparray[0]+$temparray[1];
return 
$returntime;
}
?>


Usage Example


<?
function getmicrotime() {
$temparray=split(" ",microtime());
$returntime=$temparray[0]+$temparray[1];
return 
$returntime;
}

$starttime=getmicrotime();
sleep(2);
$endtime=getmicrotime();

print 
$endtime-$starttime;
?>



Rate This Script





Search



This Category All Categories