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?
我确定这个问题已被问过一千次,这是一个相当笼统的问题,但我 我不打算调试有错误的脚本(必要),而是要以可读(或半可读)的格式逐行查看脚本的处理方式。 p>
我的想法是要很好地理解它是如何实现的,而不是将它真正地放入现实世界的场景......在每个可能的逻辑位置添加PRINT_R或VAR_DUMP回声......或者只是努力将每个可能的场景投入其中 产生PHP错误或产生不良结果的逻辑错误。 当然,这仍然会完成,但我仍然希望在调试和质量保证的过程中看到幕后发生的事情。 p>
本质上,我会 喜欢有一个工具,我可以在特定的PHP函数的开头启动,该函数将遵循脚本直到完成,并生成带有结果的日志文件或电子邮件。 再次,不仅仅是错误。 我认为这对于QA之前是很好的,但是不确定这样的事情是否存在(或者为什么不应该存在)? p>
这样的工具是否存在? p> div>
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