Library code snippets

Determine execution time in PHP

This code is based on the ASP script posted by Lio. It will determine the time taken for a php script to execute correct to 0.000000000000001 seconds.

<!-- put this at the top of the page -->
<?php
   $mtime = microtime();
   $mtime = explode(" ",$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $starttime = $mtime;
;?>

<!-- put other code and html in here -->


<!-- put this code at the bottom of the page -->
<?php
   $mtime = microtime();
   $mtime = explode(" ",$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $endtime = $mtime;
   $totaltime = ($endtime - $starttime);
   echo "This page was created in ".$totaltime." seconds";
;?>

Comments

  1. 07 Dec 2004 at 19:50

    the code simple and easy to  implement


    thanks to you!

  2. 11 Nov 2003 at 06:32

    great... very useful. thank you

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of Determine execution time in PHP.

Leave a comment

Sign in or Join us (it's free).

 gringod I was born. I lived. I got bored.... I found computers. I live again!!!

Related podcasts

  • EarthClassMail.com - Moving from LAMP to .NET 3.5

    Scott chats with Matt Davis, architect at EarthClassMail.com, about their move from a LAMP stack (Linux/Apache/mysql/PHP) to .NET 3.5. What's working, what's not, and what kinds of issues are they running into as their architect their solution.

Events coming up

  • Apr 17

    WebTech Conference 2010 - Bulgaria

    Veliko Turnovo, Bulgaria

    6th edition of WebTech conference will be held. A 2 day conference about : - Web Technologies - Blogs and blogging - Web 3.0 - Open Web - Mobile technologies - Internet Business

We'd love to hear what you think! Submit ideas or give us feedback