Version 34 (modified by Vincent Caron, 11 years ago) (diff)



  • Install Debian package with source deb phptop/ (Etch, Lenny, Squeeze, Sid)
  • Download phptop-0.4.tar.gz
  • Browse at source:/phptop/
  • Checkout with svn co svn://

phptop prints per query and average metrics comparable to the 'time' program or shell builtin: wallclock, user and system CPU time along with memory and other ressource usages.

It uses a a few lines of PHP which hook into your existing code without any changes, records per query statistics via the standard error log, then collects and prints reports with a standalone program. phptop itself is written in Perl and requires LWP.

phptop is licensed under the GNU GPL 3.0.


It can be globally activated on a LAMP server and requires little ressources and a single line configuration change in your php.ini. For instance:

server:~# echo auto_prepend_file=/path/to/phptop_hook.php >>/etc/php/php.ini
server:~# apache2ctl reload

If you install the Debian package, the setup is fully automatic (implies an 'Apache reload').

Wait a few minutes to collect enough data then run phptop.

phptop expects that PHP standard error is logged to your web server error log files (or at least via any logging mechanism). This should be the case on any sane LAMP setup, otherwise we suggest you fix it with log_errors=on in your php.ini.


On a server with several distinct vhost and applications, anlyzing last 15 minutes and sorting by average memory usage per query:

server:~$ phptop -t 15 -s mem
                                       Hit     Time     User      Sys  Mem/hit  Mem_max  Inc/hit  Inc_max                   9     14.7      7.4      2.7     39.2     39.5       75       75                66    116.1     53.0     20.7     39.8     40.5       75       75             3      0.7      0.4      0.1     14.0     14.0       72       72              22      5.1      3.1      0.5     14.0     14.0       70       72               16     24.1      2.3      0.3     15.0     16.8       71       71            98     16.0     11.9      1.8     13.8     14.0       66       66                         13      6.5      1.6      0.2     13.7     14.5       61       67                    6      2.6      1.1      0.1     14.5     14.5       72       72        5      1.3      0.7      0.1     14.8     15.5       72       74                          1      0.5      0.2      0.0     12.0     12.0       56       56

Total                                 8078   8826.9    772.5    132.7

Once the 'recorder hook' is installed, running phptop does not need specific privileges besides read access to the relevant web error log files.


phptop has only be tested on PHP 5.2.

phptop works with the regular embedded module and the CGI/FastCGI mode. There is currently no way to distinguish those different PHP calling contexts (also known as SAPI's).

The CPU user and system time are collected with the getrusage system call, with exclusion of child processes (thus forks, shell_exec and such are not accounted). The precision with Linux is limited by the kernel scheduler frequency: mostly 100Hz with 2.4 series (10ms precision) and 250Hz with 2.6 series (4ms precision). phptop is not a tracing or debugging tool, it is used to drill down among expensive queries and 10ms precision is considered sufficient for its goal. Other kernels than Linux have not been tested.

Attachments (14)

Download all attachments as: .zip