I was coding a web page which is over 600 lines of PHP codes. I was wondering how many seconds the server would take to load the web page. Because there are lot of control structures and loops to be executed.
How I achieved the need simply is described below.
Add the following code snippet to the PHP file(the line before the <html> tag starts).
$startTime = microtime(); $startArray = explode(" ", $startTime); $startTime = $startArray + $startArray;
Add the following code snippet to the PHP file(as soon the </html> tag was closed).
$endTime = microtime(); $endArray = explode(" ", $endTime); $endTime = $endArray + $endArray; $totalTimeTaken = $endTime - $startTime; $totalTimeTaken = round($totalTimeTaken,10); echo "Load Time: "; printf ("%f\n", $totalTimeTaken);
The method is simple what it does is store the time in micro seconds and get the difference when the <html> tag is printed and the </html> tag is printed. The differnence is the time required to load the page. Actually the correct word is “Total Time taken to render the page”
Stupid and Simple.