Xdebug 和 PhpStorm 与 Laravel Sail 仅调试 server.php

问题描述 投票:0回答:1

我使用 SAIL 安装了最新的 Laravel (

curl -s "https://laravel.build/example-app" | bash
)。

在我的

.env
中我添加了:

SAIL_XDEBUG_MODE=develop,debug,profile

当我在 PhpStorm 中设置“在 php 脚本中的第一行中断”设置时,脚本在

server.php
文件处停止。生成的
cachegrind.out.21
文件也仅包含
server.php

我需要做什么,才能调试原始代码而不是仅调试

server.php

在 PhpStorm 的服务器设置中,我添加了主机

localhost:80
并将项目文件映射到
/var/www/html
目录。

当我删除“在第一行停止”设置并在

public/index.php
中添加断点时,它根本没有停止。为了验证,我尝试在 VSCode 中调试,它停止在
index.php

此外我发现(并且不明白),当我从 phpstorm 中删除服务器配置并重新加载浏览器时,会出现一个窗口“来自 Xdebug 的传入连接”。服务器上提到的文件路径是

/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/resources/server.php
。但基本上这最终会出现在我已经拥有的配置中。

根据评论,我启用了日志记录:

[26] Log opened at 2023-06-05 10:03:18.607155
[26] [Config] INFO: Trigger value for 'XDEBUG_TRIGGER' not found, falling back to 'XDEBUG_SESSION'
[26] [Config] INFO: No shared secret: Activating
[26] [Step Debug] INFO: Connecting to configured address/port: host.docker.internal:9003.
[26] [Step Debug] INFO: Connected to debugging client: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port).
[26] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/resources/server.php" language="PHP" xdebug:language_version="8.2.6" protocol_version="1.0" appid="26" idekey="XDEBUG_ECLIPSE"><engine version="3.2.0"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2022 by Derick Rethans]]></copyright></init>

[26] [Step Debug] <- feature_set -i 1 -n show_hidden -v 1
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="show_hidden" success="1"></response>

[26] [Step Debug] <- feature_set -i 2 -n max_depth -v 1
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="max_depth" success="1"></response>

[26] [Step Debug] <- feature_set -i 3 -n max_children -v 100
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="3" feature="max_children" success="1"></response>

[26] [Step Debug] <- feature_set -i 4 -n extended_properties -v 1
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="4" feature="extended_properties" success="1"></response>

[26] [Step Debug] <- feature_set -i 5 -n notify_ok -v 1
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="5" feature="notify_ok" success="1"></response>

[26] [Step Debug] <- feature_set -i 6 -n resolved_breakpoints -v 1
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="6" feature="resolved_breakpoints" success="1"></response>

[26] [Step Debug] <- feature_set -i 7 -n breakpoint_include_return_value -v 1
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="7" feature="breakpoint_include_return_value" success="1"></response>

[26] [Step Debug] <- stdout -i 8 -c 1
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stdout" transaction_id="8" success="1"></response>

[26] [Step Debug] <- status -i 9
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="status" transaction_id="9" status="starting" reason="ok"></response>

[26] [Step Debug] <- step_into -i 10
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="10" status="break" reason="ok"><xdebug:message filename="file:///var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/resources/server.php" lineno="3"></xdebug:message></response>

[26] [Step Debug] <- eval -i 11 -- aXNzZXQoJF9TRVJWRVJbJ1BIUF9JREVfQ09ORklHJ10p
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="11"><property type="bool"><![CDATA[0]]></property></response>

[26] [Step Debug] <- eval -i 12 -- aXNzZXQoJF9TRVJWRVJbJ1NFUlZFUl9OQU1FJ10p
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="12"><property type="bool"><![CDATA[1]]></property></response>

[26] [Step Debug] <- eval -i 13 -- KHN0cmluZykoJF9TRVJWRVJbJ1NFUlZFUl9OQU1FJ10p
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="13"><property type="string" size="7" encoding="base64"><![CDATA[MC4wLjAuMA==]]></property></response>

[26] [Step Debug] <- eval -i 14 -- KHN0cmluZykoJF9TRVJWRVJbJ1NFUlZFUl9QT1JUJ10p
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="14"><property type="string" size="2" encoding="base64"><![CDATA[ODA=]]></property></response>

[26] [Step Debug] <- eval -i 15 -- KHN0cmluZykoJF9TRVJWRVJbJ1JFUVVFU1RfVVJJJ10p
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="15"><property type="string" size="12" encoding="base64"><![CDATA[L2Zhdmljb24uaWNv]]></property></response>

[26] [Step Debug] <- stack_get -i 16
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stack_get" transaction_id="16"><stack where="{main}" level="0" type="file" filename="file:///var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/resources/server.php" lineno="3"></stack></response>

[26] [Step Debug] <- run -i 17
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="17" status="stopping" reason="ok"></response>

[26] [Step Debug] <- detach -i 18
[26] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="detach" transaction_id="18" status="stopping" reason="ok"></response>

[26] Log closed at 2023-06-05 10:03:18.701446

配置如下:

当我删除它并重新加载浏览器时,我得到: 我接受它并稍后在路径中添加

/var/www/html

php laravel phpstorm xdebug laravel-sail
1个回答
0
投票

我因为同样的问题来到这个页面。我阅读了评论,查看了服务器日志,意识到问题所在。事实上,默认情况下,xDebug 使用

cachegrind.out.%p
作为配置文件名,其中
%p
是进程 ID,然而,Laravel 服务器使用一个进程,默认情况下配置文件每次都会被覆盖。

例如,我的浏览器向 favicon.ico 发出请求,这会删除配置文件结果:

因此,您需要将输出文件的名称更改为

cachegrind.out.%r
以随机十六进制数字结尾,或者使用
cachegrind.out.%R
将请求 uri 作为文件参数。在网站上了解更多信息 https://xdebug.org/docs/all_settings#trace_output_name

© www.soinside.com 2019 - 2024. All rights reserved.