【发布时间】:2021-11-01 06:44:18
【问题描述】:
当我停止调试时,我的 PHP 守护程序脚本继续在后台运行。当我停止调试时,如何让 xdebug 自动终止/终止我的 PHP 脚本?
我的环境:
- 带有 xdebug 扩展的 PHP 8 (cli)。
- 带有 PHP Debug 扩展名的 Visual Studio 代码。
Visual Studio 代码(settings.json):
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "PHP Debug",
"type": "php",
"request": "launch",
"program": "${workspaceFolder}/xdebug.php",
"cwd": "${workspaceFolder}",
"runtimeArgs": [
"-dxdebug.log=/tmp/xdebug.log",
],
"env": {
"XDEBUG_MODE": "debug",
"XDEBUG_TRIGGER": "true",
"XDEBUG_CONFIG": "client_port=${port}",
},
"internalConsoleOptions": "openOnSessionStart",
},
],
},
调试测试脚本(/path/to/xdebug.php):
<?php
sleep(15);
Xdebug 日志(/tmp/xdebug.log):
[101075] Log opened at 2021-09-03 18:34:25.062284
[101075] [Step Debug] INFO: Connecting to configured address/port: localhost:9003.
[101075] [Step Debug] INFO: Connected to debugging client: localhost:9003 (through xdebug.client_host/xdebug.client_port). :-)
[101075] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///path/to/xdebug.php" language="PHP" xdebug:language_version="8.0.5" protocol_version="1.0" appid="101075" idekey="true"><engine version="3.0.4"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2021 by Derick Rethans]]></copyright></init>
[101075] [Step Debug] <- feature_set -i 1 -n resolved_breakpoints -v 1
[101075] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="resolved_breakpoints" success="1"></response>
[101075] [Step Debug] <- feature_set -i 2 -n notify_ok -v 1
[101075] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="notify_ok" success="1"></response>
[101075] [Step Debug] <- feature_set -i 3 -n extended_properties -v 1
[101075] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="3" feature="extended_properties" success="1"></response>
[101075] [Step Debug] <- run -i 4
******** I stopped debugging at 18:34:30 ********
[101075] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="4" status="stopping" reason="ok"></response>
[101075] Log closed at 2021-09-03 18:34:40.243542
【问题讨论】:
-
VSCode 是否发送“停止”或“分离”协议命令?要找出答案,请使用
xdebug.log设置创建日志:xdebug.org/docs/all_settings#log 并找出答案:-) -
感谢@Detick 的回复。日志 (/tmp/xdebug.log) 中没有任何内容表明收到了停止/分离命令。在我停止调试然后记录“日志关闭”后,它完成了
sleep(15);的执行。 -
日志中不应该有
sleep(15)- 你能显示日志的最后 10 行吗? -
抱歉,
sleep(15);是我用来测试 xdebug 的脚本,并且不包含在日志中。我在上面编辑过的问题中添加了/tmp/xdebug.log,在Log closed消息前5 秒左右我停止了调试。 -
[57177] [Step Debug] <- stop -i 5— 你说“日志 (/tmp/xdebug.log) 中没有任何内容表明停止/分离命令”。它里面有stop。 Xdebug 也回复为stopped,下一个日志行是Log closed。看起来脚本终止得很好。
标签: visual-studio-code xdebug xdebug-3