[thelist] PHP microtime() vs time() vs Date("U") (was: How do you store your snippets?)
Hendrik Mans
hm at netzbiest.de
Sun Feb 11 11:13:27 CST 2001
> <tip = "PHP" Type="Timing page">
> If you want to know how long it takes to process your page on the server
> then use this.
> $startTime = date("U"); // Place at top of page
>
> $endTime = date("U"); // Place at bottom of page
> echo "<br>Total Lapsed Time: " . (( $endTime - $startTime ) / 60 ) .
> "minutes<br>";
> </tip>
And if you need a higher resolution than seconds (which you can also get via
Time() instead of Date("U"), which is really a turn around one extra corner
you could save), use microtime():
http://php.net/manual/en/function.microtime.php
Careful: microtime() returns two values (seperated by a single space) which
you must add in order to get the time since 1/1/70 in microseconds. ie:
<code>
list($fraction, $full) = explode(' ', microtime());
$start = $full + $fraction;
// do stuff
list($fraction, $full) = explode(' ', microtime());
$end = $full + $fraction;
$duration = $end - $start;
print("This script took $duration seconds to complete.");
</code>
Take care,
Hendrik
More information about the thelist
mailing list