为什么 XDebug 导致页面在 Visual Studio 代码 PHP 调试扩展中持续加载?
Why is XDebug causing page to stick loading in Visual Studio Code PHP Debug extension?
我正在尝试调试 php 中的 Visual Studio 代码。这是我安装 PHP 调试扩展(以及 PHP 和 XDebug 作为依赖项)后的第一个项目。如果我在命令提示符 "C:\php>php -S 0.0.0.0:9000 c:\users\landerson\documents\vs_proj\php_example\index.php" 中将 PHP 可执行文件作为目标文件,页面将正确呈现。但是,如果我在 Visual Studio 中使用配置 "Listen for XDebug" 开始调试,页面将一直加载,直到我停止调试过程。
我正在关注 Microsoft 的解释初始设置的博客条目:https://blogs.msdn.microsoft.com/nicktrog/2016/02/11/configuring-visual-studio-code-for-php-development/. I suspect not fully understanding the instruction "Make sure to point your webserver root to your project and each time you request a PHP file" may be what is tripping me up. I've tried with and without executing the command prompt entry. That seems to only effect what happens after I stop the debugging process. I've entered my phpinfo() results into https://xdebug.org/wizard.php 并按照说明进行操作。我在 C:\php 中既没有 index.php 也没有 php.ini 并且在 c:\users\landerson\documents\vs_proj\php_example
中都有
index.php
<?php
$myvar = "Hello ";
$myvar = $myvar . "PHP World!";
echo $myvar;
?>
php.ini
的底部
zend_extension = C:\php\ext\php_xdebug-2.6.1-7.2-vc15-nts-x86_64.dll
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
C:\Users\landerson\AppData\Roaming\Code\User\settings.json
{
//"http.proxyStrictSSL": false,
"php.validate.enable": true,
"php.validate.executablePath": "C:\php\php.exe",
"php.validate.run": "onType"
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
我希望至少在没有断点的情况下页面会加载并且添加断点会利用 PHP 调试扩展。 Visual Studio 代码似乎至少让 XDebug 开始侦听端口 9000,但无论出于何种原因,它都没有按预期进行。
所以我最终通过以下视频让它工作:https://www.youtube.com/watch?v=a14kN2u5nEk 由 Lyall van der Linde 提供。除其他错误外,我不应该将服务和扩展配置到同一个端口。
据我所知,XDebug 目前没有 PHP 32 位版本 7.3.1 的版本,所以我最终安装了旧版本 XAMPP (7.2.14)。 Windows 安装程序的旧版本可在 https://sourceforge.net/projects/xampp/files/XAMPP%20Windows/ 获得。我已经安装了最新版本的 Visual Studio 代码。我已将 PHP 调试扩展添加到 Visual Studio 代码并重新加载应用程序。
由于 IIS 使用端口 80,我打开 XAMPP 控制面板并导航到主级别配置,然后是服务和端口设置,并在 apache 选项卡下将服务名称 Apahce2.4 设置为 Main端口 8080 和 SSL 端口 443。我编辑了 C:\xampp\apache\conf\httpd.conf 并将 "Listen 80" 替换为 "Listen 8080"。然后我在XAMPP控制面板中启动了apache服务。
然后我在 C:\xampp\htdocs\ 下添加了文件夹 "phptest",并在 VSCode 中打开了该文件夹。添加文件 test.php 并添加行:
<?php
$a = 6;
$b = 3;
$c = 0;
$c = $a * $b;
echo $c;
我更新了 VSCode 用户设置如下
{
"php.validate.enable": true,
"php.validate.executablePath": "C:\xampp\php\php.exe",
"php.validate.run": "onType"
}
我打开http://localhost:8080/phptest/test.php输出为“18”。
我打开了http://localhost:8080/dashboard/phpinfo.php, copied the text of that page and pasted the results to the input form at https://xdebug.org/wizard.php。这提示我为 XDebug 下载正确的 dll(对我来说 php_xdebug-2.6.1-7.2-vc15.dll)。然后我编辑了 C:\xampp\php\php.ini 并附加到文件的末尾:
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
zend_extension = C:\xampp\php\ext\php_xdebug-2.6.1-7.2-vc15.dll
由于 php.ini 的变化,我需要在 XAMPP 控制面板中停止并重新启动 Apache 服务。然后我在Visual Studio代码的左侧导航下选择了"Debug"并添加了一个PHP配置"Listen for XDebug"并使用了默认的launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
我在test.php加了断点,在Visual Studio开始调试代码。我在浏览器中导航到 localhost:8080/phptest/test.php,我的断点在 Visual Studio 代码中命中,允许我查看变量的值并逐步执行代码。
我正在尝试调试 php 中的 Visual Studio 代码。这是我安装 PHP 调试扩展(以及 PHP 和 XDebug 作为依赖项)后的第一个项目。如果我在命令提示符 "C:\php>php -S 0.0.0.0:9000 c:\users\landerson\documents\vs_proj\php_example\index.php" 中将 PHP 可执行文件作为目标文件,页面将正确呈现。但是,如果我在 Visual Studio 中使用配置 "Listen for XDebug" 开始调试,页面将一直加载,直到我停止调试过程。
我正在关注 Microsoft 的解释初始设置的博客条目:https://blogs.msdn.microsoft.com/nicktrog/2016/02/11/configuring-visual-studio-code-for-php-development/. I suspect not fully understanding the instruction "Make sure to point your webserver root to your project and each time you request a PHP file" may be what is tripping me up. I've tried with and without executing the command prompt entry. That seems to only effect what happens after I stop the debugging process. I've entered my phpinfo() results into https://xdebug.org/wizard.php 并按照说明进行操作。我在 C:\php 中既没有 index.php 也没有 php.ini 并且在 c:\users\landerson\documents\vs_proj\php_example
中都有index.php
<?php
$myvar = "Hello ";
$myvar = $myvar . "PHP World!";
echo $myvar;
?>
php.ini
的底部zend_extension = C:\php\ext\php_xdebug-2.6.1-7.2-vc15-nts-x86_64.dll
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
C:\Users\landerson\AppData\Roaming\Code\User\settings.json
{
//"http.proxyStrictSSL": false,
"php.validate.enable": true,
"php.validate.executablePath": "C:\php\php.exe",
"php.validate.run": "onType"
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
我希望至少在没有断点的情况下页面会加载并且添加断点会利用 PHP 调试扩展。 Visual Studio 代码似乎至少让 XDebug 开始侦听端口 9000,但无论出于何种原因,它都没有按预期进行。
所以我最终通过以下视频让它工作:https://www.youtube.com/watch?v=a14kN2u5nEk 由 Lyall van der Linde 提供。除其他错误外,我不应该将服务和扩展配置到同一个端口。
据我所知,XDebug 目前没有 PHP 32 位版本 7.3.1 的版本,所以我最终安装了旧版本 XAMPP (7.2.14)。 Windows 安装程序的旧版本可在 https://sourceforge.net/projects/xampp/files/XAMPP%20Windows/ 获得。我已经安装了最新版本的 Visual Studio 代码。我已将 PHP 调试扩展添加到 Visual Studio 代码并重新加载应用程序。
由于 IIS 使用端口 80,我打开 XAMPP 控制面板并导航到主级别配置,然后是服务和端口设置,并在 apache 选项卡下将服务名称 Apahce2.4 设置为 Main端口 8080 和 SSL 端口 443。我编辑了 C:\xampp\apache\conf\httpd.conf 并将 "Listen 80" 替换为 "Listen 8080"。然后我在XAMPP控制面板中启动了apache服务。
然后我在 C:\xampp\htdocs\ 下添加了文件夹 "phptest",并在 VSCode 中打开了该文件夹。添加文件 test.php 并添加行:
<?php
$a = 6;
$b = 3;
$c = 0;
$c = $a * $b;
echo $c;
我更新了 VSCode 用户设置如下
{
"php.validate.enable": true,
"php.validate.executablePath": "C:\xampp\php\php.exe",
"php.validate.run": "onType"
}
我打开http://localhost:8080/phptest/test.php输出为“18”。
我打开了http://localhost:8080/dashboard/phpinfo.php, copied the text of that page and pasted the results to the input form at https://xdebug.org/wizard.php。这提示我为 XDebug 下载正确的 dll(对我来说 php_xdebug-2.6.1-7.2-vc15.dll)。然后我编辑了 C:\xampp\php\php.ini 并附加到文件的末尾:
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
zend_extension = C:\xampp\php\ext\php_xdebug-2.6.1-7.2-vc15.dll
由于 php.ini 的变化,我需要在 XAMPP 控制面板中停止并重新启动 Apache 服务。然后我在Visual Studio代码的左侧导航下选择了"Debug"并添加了一个PHP配置"Listen for XDebug"并使用了默认的launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
我在test.php加了断点,在Visual Studio开始调试代码。我在浏览器中导航到 localhost:8080/phptest/test.php,我的断点在 Visual Studio 代码中命中,允许我查看变量的值并逐步执行代码。