Wednesday 3 June 2009

Profiling PHP Code

I have a PHP script I wrote for my research that takes stupidly long time to run. Why? I don't know.  So on an off chance of finding something useful, I put "PHP profiling" into google.


So it turns out that PHP profiling is a huge topic, there are many websites ready to provide HOWTOs and tutorials for a zillion different techniques.  And, like everything in the computer world it seems, the solution is easy and sifting through all useless advice and "type-this-random-thing-into-your-console" is what takes the time.


Here's what gentoo users need to know:



  1. emerge xdebug

  2. Edit /etc/php/php-cli/ext/xdebug.ini , set xdebug.enable_profiling="1", and I also had to increase my max_nesting_level to "1000".  It took forever to figure this out, ALL the documents say "oh, just put the settings in php.ini.". WRONG.  They get ignored in there.

  3. Install kcachegrind, and use it to load the profile dumps now being written in /tmp/cachegrind*


Done.




0 comments:

Post a Comment