RE: How can I see where my script wasting time?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, April 17, 2006 4:17 pm, afan@xxxxxxxx wrote:
> Yes, I have indexes but can't say they are done perfectly though.
> :)

Did you test on your test server with the same number of records as
"real" and the same kind of load?...

If not, you really need to think about doing that before you deploy to
a live server, eh? :-) :-) :-)

The simplest/crudest way for a small script/application is to just
sprinkle in a bunch of calls to microtime.

In PHP5, microtime(true) is particularly simple/useful.

<?php
  $run_id = uniqid(); //To distinguish this HTTP response from others
  $benchmark['start'] = microtime(true);
  sleep(30);
  $benchmark['yawn'] = microtime(true);

  //at end of script:
  //debug or not:
  if (1){
    //to screen:
    if (1) echo "<table border=\"1\">\n";
    $start_time = $benchmark['start'];
    $previous = $start_time;
    foreach($benchmark as $event => $time){
      $delta = $time - $previous;
      $total = $time - $start_time;
      if (1) echo " 
<tr><td>$event</td><td>$delta</td><td>$total</td></tr>\n";
      //to error log:
      if (1) error_log("$run_id- $event: $delta $totla");
      $previous = $time;
    }
    if (1) echo "</table>\n";
  }
?>

It usually is as simple as that, because you'll find one MONSTER thing
taking up all the CPU time, and the rest taking up micro-seconds and
not worth worrying about.

You can change some of the 1 to 0 to turn them on/off.

You'd have to call microtime() and fill up $benchmark with a hell of a
lot of entries for this to impact your script in any meaningful way.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux