Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PHP profiler

2 views
Skip to first unread message

Mladen Gogala

unread,
Dec 17, 2005, 4:29:04 PM12/17/05
to
I'm looking for a GPL licensed PHP profiler. The best thing around,
except the commercial goodies from NuSphere, seems to be Carl Taylor's
toolkit at http://www.adepteo.net/profiler/index.php
Any experiences? Does anybody here uses profiler to see where the
application time is spent and which components need fine tuning?

--
http://www.mgogala.com

Chung Leong

unread,
Dec 17, 2005, 9:14:50 PM12/17/05
to
Here is a simple profiler I wrote. It uses a tick function to measure
the time expired between each PHP operation and debug_back_trace() to
find out where it occurs. Kinda neat as you don't have to make much
modification. Just include it at the beginning of the script, then at
the end, call __profile__('get') to obtain the profile data--an
associative array of percentages keyed by function names.

profiler.php:
<?php

function __profiler__($cmd = false) {
static $log, $last_time, $total;
list($usec, $sec) = explode(" ", microtime());
$now = (float) $usec + (float) $sec;
if($cmd) {
if($cmd == 'get') {
unregister_tick_function('__profile__');
foreach($log as $function => $time) {
if($function != '__profile__') {
$by_function[$function] = round($time / $total * 100, 2);
}
}
arsort($by_function);
return $by_function;
}
else if($cmd == 'init') {
$last_time = $now;
return;
}
}
$delta = $now - $last_time;
$last_time = $now;
$trace = debug_backtrace();
$caller = $trace[1]['function'];
@$log[$caller] += $delta;
$total += $delta;
}

__profiler__('init');
register_tick_function('__profiler__');
declare(ticks=1);

?>

Chung Leong

unread,
Dec 17, 2005, 9:24:39 PM12/17/05
to
Forgot to mention that as tick functions don't work in a threaded
environment, you'll need to set up PHP as CGI if you're on Windows.

R. Rajesh Jeba Anbiah

unread,
Dec 19, 2005, 11:51:10 PM12/19/05
to

Never tried. But, I use APD <http://in.php.net/apd>. It's neat, but
lacks GUI. We use our own GUI (can't give, sorry).

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

R. Rajesh Jeba Anbiah

unread,
Dec 19, 2005, 11:53:03 PM12/19/05
to
Chung Leong wrote:
> Here is a simple profiler I wrote.
<snip>

Hard core programmers like you'll always write codes and would
restrain to use other tools:( But, I would suggest you to try APD
<http://in.php.net/apd> and see the difference.

Mladen Gogala

unread,
Dec 20, 2005, 10:55:50 AM12/20/05
to
On Mon, 19 Dec 2005 20:51:10 -0800, R. Rajesh Jeba Anbiah wrote:

> Never tried. But, I use APD <http://in.php.net/apd>. It's neat, but
> lacks GUI. We use our own GUI (can't give, sorry).

APD is a debugger, not a profiler. Thanks.

--
http://www.mgogala.com

Andy Hassall

unread,
Dec 20, 2005, 11:19:29 AM12/20/05
to

"APD is the Advanced PHP Debugger. It was written to provide profiling and
debugging capabilities for PHP code"

And it goes on with an example of profiling later on the page.

--
Andy Hassall :: an...@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

0 new messages