|
||||||||||||||
|
||||||||||||||
You probably wonder how much time is needed for your PHP page to load. It can be crucial for your web server if your php scripts load slow and take most of the CPU and RAM resources. It is also a good idea to measure parts of your PHP code which can cause delays such as for/while cycles, writing/reading to/from files or MySQL database.
Using microtime() PHP function you will know exactly how much time is needed for your PHP code to be executed. Follow the steps below to put the PHP code on your web page:
Put the following code at the very top of your PHP page (if you measure the time needed for particular part of the code put this right before that PHP code part)
The following code has to be put at the very end of the web page (or the end of the PHP code part)
Now, when you access your web page you will know the time needed for it to execute. This is an example output of what you are going to see:
Page generated in 0.0031 seconds.
| Comments |
| Code posted on August 17, 2010, 10:56 pm |
| function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } |
| iptables posted on June 4, 2010, 4:20 pm |
| i use thdev 2009(Final) Page generated in '1275657082.0379' seconds. these is what i get but my page is loading in 1 second |
| David Rivet posted on March 21, 2010, 2:12 am |
| My time is being displayed top left above my banner. How can I get it to be displayed center of page as the very last thing on the page site? http://acadiasgarden.net Best Regards David 'stormy' Rivet |
| David Rivet posted on March 21, 2010, 2:11 am |
| My time is being displayed top left above my banner. How can I get it to be displayed center of page as the very last thing on the page site? http://acadiasgarden.net Best Regards David 'stormy' Rivet |
| tony posted on March 1, 2010, 2:02 am |
| helper is correct, for PHP5. example: $start_time = microtime(true); ... $end_time = microtime(true); echo "Page generated in " . round(($end_time - $start_time),5) . " seconds\n"; |
| andrey posted on December 29, 2009, 10:55 am |
| for Sean PHP Tag <? - ?> works for PHP 4 and below, PHP 5 and above require <?php - ?> |
| helper posted on December 24, 2009, 1:08 am |
| Dude, you could use microtime(true). It returns double value: sec.millisec. |
| Sean posted on November 12, 2009, 10:24 pm |
| You forgot to add <?php to the beginning tags. It wasn't working for me until I added php to the beginning tag. The beginning tags suppose to be like this <?php not <?. |
| www.dousti.com posted on September 12, 2009, 2:03 pm |
| it is best... I need a way for measure my web site visitor`s internet speed sorry my EN languege is limited. |
| HK posted on August 25, 2009, 11:12 pm |
| Very nice thank you for posting this... |