Reputation: 28648
I would like to see a log of THE WHOLE code execution of PHP script(s). Something like this: http://en.wikibooks.org/wiki/Ruby_Programming/Standard_Library/Tracer (for lack of better example; no flame please).
Is there some way how to obtain the log in PHP?
Note: I know I can use a debugger but that's not the same.
Upvotes: 28
Views: 60109
Reputation: 8863
This is what I need to traces all the lines when running php or Laravel framework in windows sub-system for linux (WSL).
Install xdebug
in the system then edit /etc/php/7.4/mods-available/xdebug.ini
with the following details
zend_extension=xdebug.so
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_connect_back=1
xdebug.remote_port = 9001
xdebug.scream=0
xdebug.cli_color=1
xdebug.show_local_vars=1
xdebug.remote_autostart=1
; this part here, above is used for line by line debug in vscode
xdebug.auto_trace=1
xdebug.trace_output_dir = /mnt/c/projects/www/phptraces
xdebug.trace_output_name=trace.%u
xdebug.collect_params=4
xdebug.trace_format = 1
This one here
xdebug.trace_output_dir = /mnt/c/projects/www/phptraces
is the path where to store logs
For laravel framework it generate very large file most likely 4GB in size. So I used
split -l 1000 trace.1576842503_368392.xt pieces/traces
to split it into smaller parts containing 1000 lines each and store it into pieces directory.
Then you can use editor find in files what your looking for
Upvotes: 0
Reputation: 2374
Have a look at Kint.
It's var_dump() and debug_backtrace() on steroids. Easy to use, but powerful and customizable. An essential addition to your development toolbox.
it also has platform specific extensions here
Upvotes: 5
Reputation: 146302
In any function you can see the whole backtrace by using debug_backtrace(...)
Or you can use Xdebug profiler to profile your PHP scripts.
Upvotes: 8
Reputation: 11
You can use a PHP extension called : XHProf, developed by Facebook.
It is capable of reporting function-level call counts and inclusive and exclusive wall time, CPU time and memory usage.
https://github.com/facebook/xhprof
Upvotes: 1
Reputation: 2434
Xdebug is definitely what you want, but with something like callgrind from the valgrind suite as well.
Zend blog post here should give you some pointers: http://devzone.zend.com/1139/profiling-php-applications-with-xdebug/
Upvotes: 10