When I stop debugging, my PHP daemon script continues to run in the background. How do I make xdebug automatically terminate/kill my PHP script when I stop debugging?
My environment:
- PHP 8 (cli) with the xdebug extension.
- Visual Studio Code with the PHP Debug extension.
Visual Studio Code (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",
},
],
},
Debugging test script (/path/to/xdebug.php):
<?php
sleep(15);
Xdebug log (/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