In python, one can trace all the statements that are executed by a command line script using the trace module. In bash you can do the same with set -x
. We have a PHP script that we're running from the command line, like a normal bash / python / perl / etc script. Nothing web-y is going on.
Is there anyway to get a trace of all the lines of code that are being executes?
I'm kinda blind here but I guess one way you could do it is to write all the relevant code inside custom functions and call debug_backtrace(). debug_print_backtrace may also be useful.
I hope it helps.
There is a PECL extension, apd, that will generate a trace file.
Not in pure-PHP, no -- as far as i know.
But you can use a debugger ; a nice way to do that is with
Both of those are free, btw.
With those, you can do step by step, set up breakpoints, watch the content of variables, view stack traces, ... And it works both for Web and CLI scripts ;-)
Of course, it means having Eclipse running on the machine you are executing your script... But if you are executing it on your development machine, you probably have a GUI and all that, so it should be fine...
(I know that, for web applications, you can have Eclipse running on a different machine than the one with the PHP webserver -- don't know if it's possible in CLI, though)
As a sidenote : maybe you can integrate Xdebug with a CLI-based debugger ; see the page I linked to earlier for a list of supported tools.