Home > Article > Backend Development > PHP Get Script Running Time_PHP Tutorial
header("content-type:text/html;charset=utf-8");
//microtime— Returns the current Unix Timestamp and microseconds
$oldtime = microtime(true);
echo "The running time of this script is:";
$v=0;
for ($i = 0; $i
$v++;
}
$newtime =microtime(true);
//Get the time difference
$runtime = $newtime-$oldtime;
//Convert timestamp to string—var_export Output or return a string representation of a variable
$runtime=var_export($runtime);
//Intercept the string substr_count and calculate the number of occurrences of the string
$postion = substr_count($runtime, 'E');
$runtime = substr($runtime,0,$postion-1);
//Convert string value to floatfloatval — Get the floating point value of a variable
$runtime = floatval($runtime)/1000;
echo $runtime."seconds";
?>