Welcome Back to shortlearner.com
today we will see how to measure the loading time of a PHP page.
the below script is very useful for determining for your web server, if your php scripts loading time
is slow, it will take most of the CPU and RAM Resources.
Php provides us a very useful function to determine exactly how much time is needed for your php code
to be executed.
put the below script on the top of your php page.
<?php $time = microtime(); $time = explode(' ', $time); $time = $time + $time; $start = $time; ?>
if you want to determine the time for particular part of the code put the above code before that
php code part.
the following script has to be put at the end of the web page or the end of the php code part.
<?php $time = microtime(); $time = explode(' ', $time); $time = $time + $time; $finish = $time; $total_time = round(($finish - $start), 4); echo 'the Page generated time is '.$total_time.' seconds.'; ?>
Now when you run your php code you will get the time for it execute.