tags:

views:

52

answers:

4

I'm looking for a solution to profile my php scripts within the browser (rather than having to use *cachegrind)

I saw this a while ago http://particletree.com/features/php-quick-profiler/, but i have no idea how good it is (or accurate)

tips/advice appreciated

A: 

I've used Benchmark on different sites, for quick & easy profiling - it works as expected: not great, but good enough for my needs.

Björn
+1  A: 

Can you use XDebug? If so, you can use this technique, which I think is as effective as any profiler.

In a profiler, don't look for accuracy of timing measurements. That is usually bought at the expense of accuracy of finding the problem.

Mike Dunlavey
yes i have xdebug installed, thanks for the link, i'll take a look
mononym
+2  A: 

xdebug generates cachegrind files, so you will likely want to avoid that. I currently use XHProf http://mirror.facebook.net/facebook/xhprof/doc.html as it includes a great web interface for seeing profiling results.

Jason
thanks looks interesting, will give it a go
mononym
A: 

I am using as simple code as this one.
Just $TIMER['mark']=microtime(TRUE); all other the code:

<?
$TIMER['start']=microtime(TRUE);
// some code
$TIMER['q1 start']=microtime(TRUE);
  $res=mysql_query($query);
$TIMER['q1 end']=microtime(TRUE);  
// some code
$TIMER['q2 start']=microtime(TRUE);
  $res=mysql_query($query);
$TIMER['q2 end']=microtime(TRUE);  
// some code
$TIMER['pagination']=microtime(TRUE);  
?>

and then simple table with results:

<?
if ('127.0.0.1' === $_SERVER['REMOTE_ADDR']) {
  echo "<table border=1><tr><td>name</td><td>so far</td><td>delta</td><td>per cent</td></tr>";
  reset($TIMER);
  $start=$prev=current($TIMER);
  $total=end($TIMER)-$start;
  foreach($TIMER as $name => $value) {
    $sofar=round($value-$start,3);
    $delta=round($value-$prev,3);
    $percent=round($delta/$total*100);
    echo "<tr><td>$name</td><td>$sofar</td><td>$delta</td><td>$percent</td></tr>";
    $prev=$value;
  }
    echo "</table><>";
}
?>

It isn't as comprehensive as xDebug output, but it can find a bottleneck and I need nothing more.

Col. Shrapnel