I’m looking for a utility similar to gprof that will generate a call graph for PHP code. I’d prefer something that can produce graphical output, or at least text output that can be interpreted by GraphViz or similar, but I’ll settle for plain text output.
Does anyone know of any tool that can do this?
I would definitely try Doxygen. It has support for PHP, and the call graphs and caller graphs it creates have been very useful in exploring “foreign code” for me previously.
Not sure there exists anything that can analyse source-code written in PHP to generate that… But there is a possiblity, when you are running the code.
And this one is able to generate some kind of callgraphs.
It can also be integrated with PHPUNit, to generate code-coverage when running unit-tests
Some time ago, PHPUnit was able to generate some callgraphs with graphviz ; I don’t find that option anymore, though 🙁
As noted already, Doxygen can generate call graphs.
Xdebug can generate function traces. These differ from doxygen’s graphs in that they are generated from runtime code, whereas doxygen is generated statically. I don’t know of any tools that can turn the function traces into a visual representation, although it shouldn’t be that hard to do.
There is also the bytekit extension, which primary function is to show the bytecode that php source code will generate. It can show this in a graph, that is essentially a callgraph.
This is an old topic – but in case anyone finds it useful….
kKCachegrind will produce callgraphs shown the actual execution threads.
PHPCallGraph is a fairly simple around graphviz which perfroms static analysis
There’s also my own effort which is similar to PHPCallGraph but adds information about loops/conditional structures and provides a method for adding callbacks to nodes. Some example scripts are bundled with the toolkit – but you can also embed it in your own scripts.
If you need something interactive, check out the new nWire for PHP. It is an Eclipse plugin which works with either PDT 2.1 and Zend Studio 7.0.