vim 我需要调试PHP,我的最佳选择是什么?

v09wglhw  于 2022-11-11  发布在  PHP
关注(0)|答案(5)|浏览(145)

我在Linux环境(Debian)下做一个网站,我不是LinuxMaven,但我可以处理它,这个网站是用PHP,MySQL,HTML等制作的。
问题是,我在服务器端使用PHP。现在,为了测试,我在我的PC上安装了Apache,这样我就可以测试所有的东西。但是,如果我能调试PHP代码就太好了。到目前为止,我还不需要它,但是现在代码越来越大,它是必须的。
到目前为止,我使用的是vim,一切都很好,但是,在我的情况下,我如何调试PHP?我应该安装什么工具?它们是免费的吗?
基本上,我需要知道在我的情况下什么是最好的选择。

1yjd4xko

1yjd4xko1#

XDebug提供了逐步调试,可以用于eclipse PDT,netbeans甚至vim。你真的应该给予。还有Zend调试器。

vwkv1x7d

vwkv1x7d2#

您可以安装带有调试工具的PHP IDE。它将帮助您一步一步地调试PHP代码。
很少有哪一种流行具有这种功能:

对于更高级的解决方案,您可以手动安装XDebug扩展。
默认情况下,当XDebug被加载时,它会自动向你显示回溯,以防出现致命错误。或者你跟踪到文件(xdebug.auto_trace)中,对整个请求进行一个非常大的回溯,或者做一个分析(xdebug.profiler_enable)或other settings。如果跟踪文件太大,你可以使用xdebug_start_trace()和xdebug_stop_trace()来转储部分跟踪。

安装

使用PECL:

pecl install xdebug

在Linux上:

sudo apt-get install php5-xdebug

在Mac上(使用自制软件):

brew tap josegonzalez/php
brew search xdebug
php53-xdebug

矿井配置示例:

[xdebug]

; Extensions
extension=xdebug.so
; zend_extension="/YOUR_PATH/php/extensions/no-debug-non-zts-20090626/xdebug.so"
; zend_extension="/Applications/MAMP/bin/php/php5.3.20/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so" ; MAMP

; Data
xdebug.show_exception_trace=1       ; bool: Show a stack trace whenever an exception is raised.
xdebug.collect_vars = 1             ; bool: Gather information about which variables are used in a certain scope.
xdebug.show_local_vars=1            ; int: Generate stack dumps in error situations.
xdebug.collect_assignments=1        ; bool: Controls whether Xdebug should add variable assignments to function traces.
xdebug.collect_params=4             ; int1-4: Collect the parameters passed to functions when a function call is recorded.
xdebug.collect_return=1             ; bool: Write the return value of function calls to the trace files.
xdebug.var_display_max_children=256 ; int: Amount of array children and object's properties are shown.
xdebug.var_display_max_data=1024    ; int: Max string length that is shown when variables are displayed.
xdebug.var_display_max_depth=3      ; int: How many nested levels of array/object elements are displayed.
xdebug.show_mem_delta=0             ; int: Show the difference in memory usage between function calls.

; Trace
xdebug.auto_trace=0                 ; bool: The tracing of function calls will be enabled just before the script is run.
xdebug.trace_output_dir="/var/log/xdebug" ; string: Directory where the tracing files will be written to.
xdebug.trace_output_name="%H%R-%s-%t"     ; string: Name of the file that is used to dump traces into.

; Profiler
xdebug.profiler_enable=0            ; bool: Profiler which creates files read by KCacheGrind.
xdebug.profiler_output_dir="/var/log/xdebug"  ; string: Directory where the profiler output will be written to.
xdebug.profiler_output_name="%H%R-%s-%t"      ; string: Name of the file that is used to dump traces into.
xdebug.profiler_append=0            ; bool: Files will not be overwritten when a new request would map to the same file.

; CLI
xdebug.cli_color=1                  ; bool: Color var_dumps and stack traces output when in CLI mode.

; Remote debugging
xdebug.remote_enable=off            ; bool: Try to contact a debug client which is listening on the host and port.
xdebug.remote_autostart=off         ; bool: Start a remote debugging session even GET/POST/COOKIE variable is not present.
xdebug.remote_handler=dbgp          ; select: php3/gdb/dbgp: The DBGp protocol is the only supported protocol.
xdebug.remote_host=localhost        ; string: Host/ip where the debug client is running.
xdebug.remote_port=9000             ; integer: The port to which Xdebug tries to connect on the remote host.
xdebug.remote_mode=req              ; select(req,jit): Selects when a debug connection is initiated.
xdebug.idekey="xdebug-cli"          ; string: IDE Key Xdebug which should pass on to the DBGp debugger handler.
xdebug.remote_log="/var/log/xdebug.log" ; string: Filename to a file to which all remote debugger communications are logged.
b4wnujal

b4wnujal3#

具体来说,如果您(像我这样的新手,在第一次开始使用PHP后发现了这个SO线程,并且正在)试图找出最初生成错误消息的原因,请从error_log()开始。该函数将字符串作为 “将错误消息发送到Web服务器的错误日志或文件"
这是PHP SAPI标准错误处理(即日志记录),默认情况下进行配置。
一般来说,要学习PHP中错误报告和配置的基础知识,请从Error Handling Functions documentation on PHP.net中的函数开始-petrov dot michael () gmail com在该页上的注解是一个很有帮助的起点。
要真正生成错误,作为新手(也就是说,要阅读的文档最少),最好的选择是从print_r开始,将print_r的第二个参数设置为TRUE将返回一个字符串,然后可以将其传递给error_log

error_log('what gives $blue: ' . print_r($blue, true));

这可能给予最快的调试方法,因为PHP代码可能位于某个添加了各种输出控制层的框架中(如Wordpress)。

bprjcwpo

bprjcwpo4#

如果 您 使用 apache 作为 Web 服务 器 , 那么 您 可以 使用 apache 日志 来 查看 阻止 PHP 脚本 成功 执行 的 任何 错误 。
你 可以 用

tail -f /var/log/apache2/error.log

中 的 每 一 个
以 查看 Apache 日志 , 这 将 完成 这项 工作 ( 至少 对于 PHP 相关 错误 的 子集 ) 。

bjp0bcyl

bjp0bcyl5#

如果你的PC操作系统是Windows,那么最简单的方法是使用CodeLobster免费版与任何Web开发堆栈(WAMP,XAMPP)我发现,设置CodeLobster调试是非常容易的(相比eclipse或netbeans)和CodeLobster安装是非常小的相比,其他IDE以及,此外,它的免费版本支持完整的调试功能。
你可以在下面的文章How to debug PHP - Easy way中找到详细的安装步骤指南。

相关问题