xdebug 在 Laravel 中完全不会在控制器中中断。

huangapple go评论62阅读模式
英文:

xdebug not breaking in controller at all using laravel

问题

我正在尝试在Visual Studio Code中使用xdebug,但一切都不起作用。我已安装并启用了xdebug,以及Visual Studio Code扩展PHP Debug。请查看我的设置并指导我是否有错。

php.ini设置:

[xDebug]
zend_extension="C:\laragon\bin\php\php-8.0.24-Win32-vs16-x64\ext\php_xdebug.dll"
xdebug.mode=debug
xdebug.start_with_request=Yes
;xdebug.client_port=80
;xdebug.remote_port=80
xdebug.log="C:\laragon\debug.log"
xdebug.log_level=7
xdebug.idekey=VSCODE
xdebug.client_host="mysite.test"

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 80,
            "pathMappings": {
                "C:/laragon/www/adamjee": "${workspaceFolder}",
            },
            "ignore": [
                "**/vendor/**/*.php"
            ]
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 0,
            "runtimeArgs": [
                "-dxdebug.start_with_request=yes"
            ],
            "env": {
                "XDEBUG_MODE": "debug,develop",
                "XDEBUG_CONFIG": "client_port=${port}"
            }
        },
        {
            "name": "Launch Built-in web server",
            "type": "php",
            "request": "launch",
            "runtimeArgs": [
                "-dxdebug.mode=debug",
                "-dxdebug.start_with_request=yes",
                "-S",
                "localhost:0"
            ],
            "program": "",
            "cwd": "${workspaceRoot}",
            "port": 9003,
            "serverReadyAction": {
                "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
                "uriFormat": "http://localhost:%s",
                "action": "openExternally"
            }
        }
    ]
}

请指导我是否存在问题。

英文:

I am trying to use xdebug with visual studio code.

but nothing is working out.
Installed and enabled xdebug and I am a visual Studio code extension PHP debug.
Please review my setting below and guide me if I am doing something wrong.

php.ini settings

[xDebug]
zend_extension="C:\laragon\bin\php\php-8.0.24-Win32-vs16-x64\ext\php_xdebug.dll"
xdebug.mode=debug
xdebug.start_with_request=Yes
;xdebug.client_port=80
;xdebug.remote_port=80
xdebug.log="C:\laragon\debug.log"
xdebug.log_level=7
xdebug.idekey=VSCODE
xdebug.client_host="mysite.test"

launch.json

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "Listen for Xdebug",
        "type": "php",
        "request": "launch",
        "port": 80,
        "pathMappings": {
            "C:/laragon/www/adamjee": "${workspaceFolder}",
        },
        "ignore": [
            "**/vendor/**/*.php"
        ]
    },
    {
        "name": "Launch currently open script",
        "type": "php",
        "request": "launch",
        "program": "${file}",
        "cwd": "${fileDirname}",
        "port": 0,
        "runtimeArgs": [
            "-dxdebug.start_with_request=yes"
        ],
        "env": {
            "XDEBUG_MODE": "debug,develop",
            "XDEBUG_CONFIG": "client_port=${port}"
        }
    },
    {
        "name": "Launch Built-in web server",
        "type": "php",
        "request": "launch",
        "runtimeArgs": [
            "-dxdebug.mode=debug",
            "-dxdebug.start_with_request=yes",
            "-S",
            "localhost:0"
        ],
        "program": "",
        "cwd": "${workspaceRoot}",
        "port": 9003,
        "serverReadyAction": {
            "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
            "uriFormat": "http://localhost:%s",
            "action": "openExternally"
        }
    }
]

}

please guide where I am doing wrong.

xdebug logs

    [14160] Log opened at 2023-07-27 12:26:08.027714
[14160] [Step Debug] INFO: Connecting to configured address/port: adamjee.test:80.
[14160] [Step Debug] INFO: Connected to debugging client: adamjee.test:80 (through xdebug.client_host/xdebug.client_port).
[14160] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///C:/laragon/www/adamjee/index.php" language="PHP" xdebug:language_version="8.0.24" protocol_version="1.0" appid="14160" idekey="VSCODE"><engine version="3.2.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2023 by Derick Rethans]]></copyright></init>

[14160] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

[13228] Log opened at 2023-07-27 12:26:09.225547
[13228] [Step Debug] INFO: Connecting to configured address/port: adamjee.test:80.
[14160] Log closed at 2023-07-27 12:26:09.226357

[13228] [Step Debug] INFO: Connected to debugging client: adamjee.test:80 (through xdebug.client_host/xdebug.client_port).
[13228] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///C:/laragon/www/adamjee/index.php" language="PHP" xdebug:language_version="8.0.24" protocol_version="1.0" appid="13228" idekey="VSCODE"><engine version="3.2.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2023 by Derick Rethans]]></copyright></init>

[13228] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

[13228] Log closed at 2023-07-27 12:26:13.534187

[13228] Log opened at 2023-07-27 12:26:13.661112
[13228] [Step Debug] INFO: Connecting to configured address/port: adamjee.test:80.
[13228] [Step Debug] INFO: Connected to debugging client: adamjee.test:80 (through xdebug.client_host/xdebug.client_port).
[13228] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///C:/laragon/www/adamjee/index.php" language="PHP" xdebug:language_version="8.0.24" protocol_version="1.0" appid="13228" idekey="VSCODE"><engine version="3.2.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2023 by Derick Rethans]]></copyright></init>

[13228] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

[13228] Log closed at 2023-07-27 12:26:15.526825

[13228] Log opened at 2023-07-27 12:26:15.544789
[13228] [Step Debug] INFO: Connecting to configured address/port: adamjee.test:80.
[13228] [Step Debug] INFO: Connected to debugging client: adamjee.test:80 (through xdebug.client_host/xdebug.client_port).
[13228] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///C:/laragon/www/adamjee/index.php" language="PHP" xdebug:language_version="8.0.24" protocol_version="1.0" appid="13228" idekey="VSCODE"><engine version="3.2.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2023 by Derick Rethans]]></copyright></init>

[13228] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

[13228] Log closed at 2023-07-27 12:26:16.975555

答案1

得分: 1

以下是您的php.ini配置中需要更改的部分:

;xdebug.client_port=80
;xdebug.remote_port=80

以及您的launch.json中需要更改的部分:

"port": 80,

这两者都是错误的,请将它们移除。


Xdebug需要连接到您的IDE正在侦听的端口。默认情况下,这是9003,这也是VS Code的默认端口。请从您的配置中删除此行:

现在,您正在指示Xdebug连接到端口80(根据您的日志,它正在这样做):

[13228] [Step Debug] INFO: Connected to debugging client: adamjee.test:80 (through xdebug.client_host/xdebug.client_port).
[13228] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///C:/laragon/www/adamjee/index.php" language="PHP" xdebug:language_version="8.0.24" protocol_version="1.0" appid="13228" idekey="VSCODE"><engine version="3.2.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2023 by Derick Rethans]]></copyright></init>

但那是您的web服务器在那里侦听,并且您的Web服务器不理解Xdebug协议,因此在困惑了两秒钟后关闭连接:

[13228] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>
[13228] Log closed at 2023-07-27 12:26:15.526825
英文:

The following bits in your php.ini configuration:

;xdebug.client_port=80
;xdebug.remote_port=80

and in your launch.json:

"port": 80,`

Are both wrong. Remove them.


Xdebug needs to connect to a port that your IDE is listening on. This is by default 9003, which is also what VS Code has as default. Please remove this line from your configuration.

Right now, you're instructing Xdebug to connect to port 80 (which your logs indicate that it is doing):

[13228] [Step Debug] INFO: Connected to debugging client: adamjee.test:80 (through xdebug.client_host/xdebug.client_port).
[13228] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///C:/laragon/www/adamjee/index.php" language="PHP" xdebug:language_version="8.0.24" protocol_version="1.0" appid="13228" idekey="VSCODE"><engine version="3.2.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2023 by Derick Rethans]]></copyright></init>

But that is your web server listening there, and your web server doesn't understand the Xdebug protocol, and hence then closes the connection after two seconds of being confused:

[13228] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>
[13228] Log closed at 2023-07-27 12:26:15.526825

huangapple
  • 本文由 发表于 2023年7月27日 20:03:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76779545.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定