Home php PHP script execution time

PHP script execution time




How to correctly read the script execution time and display it in the browser?

Answer 1, authority 100%

There is only one problem with time: the time to “start” the timer. Either it does not go at the very beginning of the script, or it dangles somewhere in a separate variable, and at the same time it still does not capture the time that the script was initialized. But in general, everything is done like this:


$ start = microtime (true);
// include all the necessary files

footer.php (or wherever you want to display the time)

$ time = microtime (true) - $ start; // now the $ time variable contains a float with the value of the script execution in seconds. the matter remained with the banal number_format () and echo.

Answer 2, authority 92%

We throw this code at the beginning of the script

$ start = microtime (true);

And this is at the very end of the script (rounded to 4 decimal places)

echo 'Script execution time:' .round (microtime (true) - $ start, 4). ' sec. ';

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions