debugging 使用vscode和xcode,使用composer和skeleton创建PHP精简项目

zf9nrax1  于 6个月前  发布在  Vscode
关注(0)|答案(1)|浏览(102)

我是一个PHP新手,我正在用PHP slim开发一个API。
我使用Visual Studio Code作为IDE和PHP扩展。
PHP中正确安装了xplayer,并且在使用XAMPP运行时,debug可以完美地运行像这样的简单代码

<?php

$fisrt= 5;

$second= 7;

$result = sum($first, $second);

echo $result;


function sum($a, $b)
{
    $c = $a +$b;
    return $c;
}

字符串
但我被困在调试一个苗条的项目。我用composer创建了一个项目:

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 composer:2.1.9 php:8.0.11 slim:4.7操作系统:windows 10

ncecgwcz

ncecgwcz1#

在我的例子中,调试器正在运行,但没有任何东西在断点处停止
我找到了一个帮助我的东西here
解决方案:修复cwd路径;不要使用index.php作为程序
所以我把这个内容粘贴到我的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启动调试器,一切正常,现在我可以调试和设置断点了!

干杯,希望这对某人有帮助!

相关问题