Why should I rely on PHPJabbers.com for all my PHP scripting needs? What do you offer me when buying some script?
  • Top quality scripts
  • Full demo before buying
  • Best pricing
  • Script customization
  • 7 days a week support
  • Installation support
  • Secure buying
  • Measuring PHP page load time

    posted on 2006-05-17 16:35:12

    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)

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

    The following code has to be put at the very end of the web page (or the end of the PHP code part)

    <?
    $time = microtime();
    $time = explode(' ', $time);
    $time = $time[1] + $time[0];
    $finish = $time;
    $total_time = round(($finish - $start), 4);
    echo '<p>Page generated in '.$total_time.' seconds.</p>'."\n";
    ?>

    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
    Jonah Turnquist posted on 2008-05-04 08:27:15
    Thanks for the script, I just google for this page whenever I need to use it.

    Alex posted on 2008-04-24 07:59:15
    Thanks for the script, very helpful.

    Wendelmaques posted on 2007-12-23 15:18:10
    Thak you!

    jpino80 posted on 2007-07-20 19:34:53
    Thank you very much for this little script. It helped me figure out which part of one of my scripts was running slow.

    Pages:   1
       
    If you have any additions, suggestions or modifications for this example please send an email to or use the form below.
       
    Your name:
    Your email: (email address will not be posted on the web site)
    Comment:
    Verification