【发布时间】:2013-01-15 16:04:31
【问题描述】:
我想查看 PHP 脚本的整个代码执行的日志。像这样的东西:http://en.wikibooks.org/wiki/Ruby_Programming/Standard_Library/Tracer(因为没有更好的例子;请不要火焰)。
有没有办法在PHP中获取日志?
注意:我知道我可以使用调试器,但不一样。
【问题讨论】:
我想查看 PHP 脚本的整个代码执行的日志。像这样的东西:http://en.wikibooks.org/wiki/Ruby_Programming/Standard_Library/Tracer(因为没有更好的例子;请不要火焰)。
有没有办法在PHP中获取日志?
注意:我知道我可以使用调试器,但不一样。
【问题讨论】:
Xdebug 绝对是你想要的,但也有像 callgrind from the valgrind suite 这样的东西。
这里的 Zend 博文应该给你一些指点:http://devzone.zend.com/1139/profiling-php-applications-with-xdebug/
【讨论】:
phptrace 是一个很棒的跟踪 php 代码执行的工具
【讨论】:
在任何函数中,您都可以使用debug_backtrace(...)查看整个回溯
或者您可以使用Xdebug profiler 来分析您的 PHP 脚本。
【讨论】:
【讨论】:
您可以使用由 Facebook 开发的名为 XHProf 的 PHP 扩展。
它能够报告函数级调用计数和包容性 以及独占的挂墙时间、CPU 时间和内存使用情况。
【讨论】:
这是我在 windows linux 子系统 (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 行的较小部分并将其存储到碎片目录中。
然后您可以使用编辑器在文件中查找您要查找的内容
【讨论】: