|
|
PHP
Tutorial
5.To
find the time of execution of a php script
-------------------------------------------------------------------
|
|
The time taken to execute a PHP script
can be found by exploding microtime() function , this gives the
microseconds and seconds separately.
Adding these two gives total start time .Then, the
script for which the execution time needs to be calculated is
placed.At the end of this script,
the end time is calculated in the same way as the
start time is calculated. The start time subtracted from the end time
gives the total execution time of the
PHP script placed in between.
It is a wise idea to use this time-script lines in
very critical applications to find out the execution time taken by the
application.
|
<?php
list($usec,$sec)=explode(" ",microtime());
$start_time=(float)$usec+(float)$sec;
function print_hello_world()
{
for($i=0;$i<30;$i++)
{
echo
"hello world ";
}
}
print_hello_world();
list($usec,$sec)=explode(" ",microtime());
$end_time=(float)$usec+(float)$sec;
$total_time=$start_time-$end_time;
echo "<br>The Time Taken To Execute This Script
is".$total_time." seconds\n";
?>
Go
To Index
|
|
|