Practical Web Programming

Thursday, February 19, 2009

PHP: How to Get the Time Elaped

Using PHP's time function, you can get the time elapsed of any process in your web application. The time function returns the current Unix timestamp.

Here's a simple script to demonstrate it.


<?php

$t1 = time();

print "Start time : ".$t1."<br>";

for ($i = 0; $i < 90000000; $i++)
{
print "";
}

$t2 = time();
print "End time : ".$t2."<br>";
print "Time elapsed (s) : ".($t2 - $t1)."<br>";

?>


The script above will output the following.


Start time : 1235100956
End time : 1235100980
Time elapsed (s) : 24

2 comments:

Robin Nixon said...

Hi Joel,

I am the auther of "Learning PHP, MySQL & JavaScript" to be published later this year by O'Reilly. They are looking for a couple of technical reviewers who know all these areas to check out the manuscript for accuracy. Please email me at robin@robinnixon.com if you would be interested in having an O'Reilly Editor contact you about this.

Thanks, and I like your blog (obviously ;)

- Robin.

Anonymous said...

Yeah, i'll read this book with pleasure.. lol

Recent Post