如何在PHP中跟踪代码执行?

时间:2013-01-15 16:04:32

标签: php tracing

我希望看到PHP脚本的WHOLE代码执行日志。这样的事情:http://en.wikibooks.org/wiki/Ruby_Programming/Standard_Library/Tracer(缺乏更好的例子;请不要火焰)。

有没有办法在PHP中获取日志?

注意:我知道我可以使用调试器,但这不一样。

6 个答案:

答案 0 :(得分:8)

Xdebug绝对是你想要的,但也有类似callgrind from the valgrind suite的东西。

Zend博客文章应该给你一些指示:http://devzone.zend.com/1139/profiling-php-applications-with-xdebug/

答案 1 :(得分:7)

phptrace是一个用于跟踪php代码执行的强大工具

答案 2 :(得分:6)

在任何功能中,您都可以使用debug_backtrace(...)

查看整个回溯

或者您可以使用Xdebug profiler来分析您的PHP脚本。

答案 3 :(得分:5)

查看Kint

debug backtrace screenshot

  

类固醇上的var_dump()和debug_backtrace()。易于使用,但功能强大且可定制。您的开发工具箱的重要补充。

它还具有特定于平台的扩展程序here

答案 4 :(得分:1)

您可以使用由Facebook开发的名为:XHProf的PHP扩展程序。

  

它能够报告功能级别的呼叫计数和包含性   独家播放时间,CPU时间和内存使用情况。

https://github.com/facebook/xhprof

答案 5 :(得分:0)

这是在Linux的Windows子系统(WSL)中运行php或Laravel框架时需要跟踪的所有行。

在系统中安装xdebug,然后使用以下详细信息编辑/etc/php/7.4/mods-available/xdebug.ini

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

这是这里

xdebug.trace_output_dir = /mnt/c/projects/www/phptraces

是存储日志的路径

对于laravel框架,它会生成非常大的文件,最大可能为4GB。所以我用

split -l 1000 trace.1576842503_368392.xt pieces/traces

将其拆分为较小的部分,每个部分包含1000行,并将其存储在pieces目录中。

然后,您可以使用编辑器在文件中查找所需内容

相关问题