我是 PHP 新手,我正在使用 PHP slim 开发 API。
我使用 Visual Studio Code 作为 IDE 和 PHP 调试扩展。
xDebug 已正确安装在 PHP 中,并且在使用 XAMPP 运行时,调试可以完美地运行像这样的简单代码
<?php
$fisrt= 5;
$second= 7;
$result = sum($first, $second);
echo $result;
function sum($a, $b)
{
$c = $a +$b;
return $c;
}
但是我一直在调试一个小项目。 我和作曲家创建了一个项目:
composer create-project slim/slim-skeleton simpleAPI
并用简单的方式运行它
composer start
> php -S localhost:8080 -t public
[Sun Oct 31 00:01:29 2021] PHP 8.0.11 Development Server (http://localhost:8080) started
应用程序可以运行,但不会在断点处停止。
launch.json 是使用 vscode 自动创建的
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003
},
{
"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"
}
}
]
vscode:1.16.2 作曲家:2.1.9 php: 8.0.11 苗条:4.7 操作系统:Windows 10
在我的例子中,调试器正在运行但是没有任何东西在断点处停止。
我发现了一些对我有帮助的东西在这里。
所以我将此内容粘贴到我的 launch.json 文件中。
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:8089"
],
"program": "",
"cwd": "${workspaceRoot}/public",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
我仅将
localhost:0
更改为 localhost:8089
,其中 8089
可以是系统中的每个可用端口。 端口 0 对我来说不起作用。
然后我通过 VS Code 启动了调试器,一切正常,现在我可以调试并设置断点了!
干杯,希望这对某人有帮助!