开发者问题收集

为什么我无法使用 Sublime Text 中的 Xdebug 调试 PHP?

2020-04-04
885

我的操作系统是 Ubuntu 18.04

我的堆栈是 XAMPP (LAMPP)。

我已按照 官方页面 所示安装了 Xdebug。我也有可以在 Chrome 中调试的扩展程序。

当我尝试调试 PHP 代码( 工具 > Xdebug > 开始调试 ,然后在 Chrome 中按 F5 ,其中我的文件位于本地服务器上)时,它不会在断点处中断。我可以看到 Xdebug 窗口,但什么也没发生。

如果我转到 工具 > Xdebug >重新启动会话 我得到一个窗口,上面写着:

Unable to start xdebug session, another application is already listening on configured port (9000)

我不知道这是否与真正的错误有关。

我调查过我必须配置一个 Xdebug.sublime-settings 文件,有一个默认文件和另一个用户,在用户中我什么都没有,默认文件如下所示:

{
// For remote debugging to resolve the file locations
// it is required to configure the path mapping
// with the server path as key and local path as value.
//
// Make sure to use absolute path when defining server path,
// because Xdebug debugger engine does not return symbolic links.
//
// Example:
// "/absolute/path/to/file/on/server" : "/path/to/file/on/computer",
// "/var/www/htdocs/example/" : "C:/git/websites/example/"
"path_mapping": {

},

// Determine which URL to launch in the default web browser
// when starting/stopping a session.
"url": "",

// An IDE key is used to identify with debugger engine
// when Sublime Text will start or stop a debugging session.
//
// This package does not filter sessions by IDE key,
// it will accept any IDE key, also ones that do not match this configured IDE key.
// It is merely used when launching the default web browser with the configured URL.
"ide_key": "sublime.xdebug",

// Host address of network interface which Sublime Text
// should listen to connect with debugger engine.
//
// By specifying "" or "0.0.0.0" as host address, Sublime Text
// will listen on all the configured network interfaces.
// This is the desired configuration when debugging
// a script that is located on a remote server.
//
// Otherwise it is recommended to use "127.0.0.1" or "localhost"
// as configuration, when debugging a script on your local machine.
// Due to the fact that by listening on all the configured
// network interfaces raises a security concern as anyone
// can access Sublime Text through the configured port.
//
// When specifying host address of network interface,
// be sure to specify an IPv4 address as Sublime Text
// will listen for connections through an IPv4 socket.
"host": "",

// Which port number Sublime Text should listen
// to connect with debugger engine.
"port": 9000,

// Maximum amount of array children
// and object's properties to return.
"max_children": 32,

// Maximum amount of
// variable data to initially retrieve.
"max_data": 1024,

// Maximum amount of nested levels to retrieve
// of array elements and object properties.
"max_depth": 1,

// Break at first line on session start, when debugger engine has connected.
"break_on_start": false,

// Break on exceptions, suspend execution
// when the exception name matches an entry in this list value.
"break_on_exception": [
    // E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR
    "Fatal error",
    // E_RECOVERABLE_ERROR (since PHP 5.2.0)
    "Catchable fatal error",
    // E_WARNING, E_CORE_WARNING, E_COMPILE_WARNING, E_USER_WARNING
    "Warning",
    // E_PARSE
    "Parse error",
    // E_NOTICE, E_USER_NOTICE
    "Notice",
    // E_STRICT
    "Strict standards",
    // E_DEPRECATED, E_USER_DEPRECATED (since PHP 5.3.0)
    "Deprecated",
    // 0
    "Xdebug",
    // default
    "Unknown error"
],

// Always close debug windows and restore layout on session stop.
"close_on_stop": false,

// Show information about super globals in context view.
"super_globals": true,

// Display property by fullname in context view.
"fullname_property": true,

// Do not show possible password values in context view.
"hide_password": false,

// Render evaluated result as parsed output instead of raw XML.
"pretty_output": false,

// Always launch browser on session start/stop.
// Note: This will only work if you have the 'url' setting configured.
"launch_browser": false,

// When launching browser on session stop do not execute script.
// By using parameter XDEBUG_SESSION_STOP_NO_EXEC instead of XDEBUG_SESSION_STOP.
"browser_no_execute": false,

// Do not use the debugging window layout.
"disable_layout": false,

// Window layout that is being used when debugging.
"debug_layout" : {
    "cols": [0.0, 0.5, 1.0],
    "rows": [0.0, 0.7, 1.0],
    "cells": [[0, 0, 2, 1], [0, 1, 1, 2], [1, 1, 2, 2]]
},

// Group and index positions for debug views.
"breakpoint_group": 2,
"breakpoint_index": 1,
"context_group": 1,
"context_index": 0,
"stack_group": 2,
"stack_index": 0,
"watch_group": 1,
"watch_index": 1,

// Custom gutter icons for indicating current line or enabled/disabled breakpoints.
//
// Do not use same icon for following values, because Sublime Text is unable
// to use the same icon for different scopes, in case there are duplicate icons
// detected it will fall back to the corresponding icon in the package.
"breakpoint_enabled": "circle",
"breakpoint_disabled": "dot",
"breakpoint_current": "",
"current_line": "bookmark",

// Path to Python installation on your system.
// Which is being used to load missing modules.
//
// It is recommended to configure your Python path for Sublime Text 2
// especially on older UNIX systems, where some modules (xml.parsers.expat)
// might be missing and could improve performance of package.
//
// Example:
// "python_path" : "/usr/lib/python2.7"
"python_path" : "",

// Show detailed log information about communication
// between debugger engine and Sublime Text.
// Log can be found at Packages/User/Xdebug.log
"debug": false

我是后端的菜鸟,我不知道如何配置该文件,而且,我是 Linux 新手,我从来没有配置过调试器(因为我只是使用 Visual Studio)。

我需要提供的任何其他技术细节,我会立即更新。

2个回答

检查您的“php.ini”并确认 xdebug 已设置为端口 9000...

在某些环境中,端口 9000 可能已被其他应用程序使用(例如,如果您正在运行 PHP-FPM,它也在端口 9000 上)。

尝试配置 PHP-XDebug 和 Sublime 以使用其他端口(例如 9003)。

Brad Kent
2021-07-18

在 XDebug 3 上,默认端口现在为 9003 。但是,它对我来说仍然不起作用。

xdebug.start_with_request = yes 对我的 Windows 设置有效

我的配置:

zend_extension="<path/to/xdebug/extension>" # A dll on Windows
xdebug.mode = debug
xdebug.show_local_vars=0
xdebug.log_level=7
xdebug.profiler_output_name=trace.%H.%t.%p.cgrind
xdebug.use_compression=false
xdebug.client_enable=1
xdebug.client_handler=dbgp
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.start_with_request = yes
Olivier
2022-11-20