Profiling PHP Code with Xdebug and KCacheGrind
In his 1974 paper, "Structured Programming with go to Statements", famed computer scientist Donald Knuth famously proclaimed premature optimization to be "the root of all evil." While it is indeed a good idea to avoid spending too much time on code optimization during the early stages of any project, eventually you'll want to seek out and resolve any bottlenecks in order to ensure your application is operating at its full potential.
Which brings us to the question of how to even go about determining which parts of an application could conceivably be optimized. One common approach involves using a profiler such as Xdebug, which can analyze your code and produce performance reports. These reports can then be reviewed within a profiling visualization tool such as KCacheGrind.
In this article I'll show you how to use Xdebug and KCacheGrind to begin profiling and analyzing your PHP-driven Web applications.