Thursday, May 15, 2008

Profile memory usage of PHP scripts

I was in need of profiling a PHP application I use to hack on (Mantis issue tracker) to determine how a certain page was eating more than 16Mb (my PHP memory limit) to load.

This turned to be very easy; for a start, I installed the xdebug package with:

yum install php-pecl-xdebug

then I edited the configuration file /etc/php.d/xdebug.ini and added:

xdebug.auto_trace = On
xdebug.show_mem_delta = On


Now I reloaded the page in the browser and got a shiny detailed report about memory consumption during the code execution in /tmp:




From that kind of report it is quite easy to spot big memory hoggers; in my case, I discovered about half of the peak memory usage (about 29Mb) is used for composing a single form control...


References:

3 comments:

  1. Memory profiling doesn't work in the newer versions of Xdebug

    ReplyDelete
  2. Right now I am using 2.0.3 in Fedora 10 without problems.

    ReplyDelete
  3. Thanks for the link, profiling worked. It seems my problems are with the PHP garbage collector being too inefficient.

    ReplyDelete