28

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.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
MartyIX
  • 27,828
  • 29
  • 136
  • 207

6 Answers6

11

phptrace is an awesome tool to trace php code executions

renenglish
  • 728
  • 1
  • 9
  • 18
  • That is interesting. Thank you for sharing. – MartyIX Jan 05 '15 at 14:47
  • 1
    I'll vote for that, because it actually answers the question, unlike the currently highest-voted answer here. Also read the documentation page for phptrace, which has a section on comparison with other tools for execution tracing. – mc0e Oct 31 '16 at 01:53
  • 1
    Sadly, an abandoned project as of 2018, which only supports PHP up to 7.1. – Gwyneth Llewelyn Apr 11 '21 at 15:22
10

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/

BenLanc
  • 2,344
  • 1
  • 19
  • 24
8

In any function you can see the whole backtrace by using debug_backtrace(...)

Or you can use Xdebug profiler to profile your PHP scripts.

Naftali
  • 144,921
  • 39
  • 244
  • 303
  • debug_backtrace is put on a specific place in a PHP script but I want to see a log of whole code execution - from start to the end. – MartyIX Jan 15 '13 at 16:07
  • 1
    Probably Didn't understand the question. The request was for an execution tracing tool. That's not like backtrace or profiling, but Xdebug **does** do execution tracing as well. – mc0e Oct 31 '16 at 01:51
5

Have a look at Kint.

debug backtrace screenshot

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

ilyar
  • 1,331
  • 12
  • 21
UXE
  • 2,374
  • 2
  • 18
  • 17
1

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

MVN
  • 11
  • 2
  • Xhprof is very useful for performance tracing on local and production environment but not for debugging other problems. – gagarine Apr 23 '15 at 12:58
0

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

Fil
  • 8,225
  • 14
  • 59
  • 85