Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

PHP Script to measure PHP execution time

Here I’ll show you how to we can show users how long it takes for php to execute that particular page.

It’s a very simple script and is accurate to 0.000000000000001 seconds.


Firstly place the following code at the very top of your page (before the tag.

< ?php
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$begintime = $time;
?>

Next add the following code at the very bottom of the page. You can change the last line to whatever you would like your viewers to see.

< ?php
$time = microtime();
$time = explode(" ", $time);
$time = $time[1] + $time[0];
$endtime = $time;
$totaltime = ($endtime - $begintime);
echo 'PHP parsed this page in ' .$totaltime. ' seconds.';
?>

COUNTER