PHP脚本调试

I'm sure this question has been asked a thousand times, and this IS a fairly general question, but I'm not looking to debug a script with errors (necessarily), but to see exactly how the script is being processed, line by line, in readable (or semi-readable) format.

The idea is to gain a good understanding of how it's playing out without actually putting it into a real-world scenario... adding PRINT_R, or VAR_DUMP echos in every possible logical location... or simply throwing every possible scenario at it in an effort to produce either a PHP error, or logical error that produces an undesired result. Of course, this will be done nonetheless, but I'd still like to see what's going on behind the scenes while still in the process of debugging and QA.

In essence, I'd like to have a tool that I can initiate at the beginning of a particular PHP function that would follow the script until completion, and produce a log file, or email, with the results. Again, NOT just the errors. I think this would be great for pre-QA, but unsure if anything like this even exists (or why it shouldn't)?

Does a tool like this exist?

Yes. You might install the php extension xdebug and start profiling your application. It's possible to dump a trace of your application. Then you can load that file into cachegrind to get a decent visualization and to inspect and analyse the number of calls and the time taken. http://www.xdebug.org/docs/profiler Like you asked, this is not about error tracking, but about the execution flow and finding possible bottlenecks, which could then be optimized.

With Xdebug it's also possible to step-debug. That means that you can execute your application in a step by step manner, while having access to all variables and their values.

There is also VLD (vulcan logic dumper) if the question includes, to see which Opcodes are thrown around. A nice online tool for this use case is also http://3v4l.org/am3S3/vld#tabs