0 引言
目前手動將 PHP 由 7.1.x 升級到 7.2.y 后,VS Code 中的 xdebug 無法使用,用 phpinfo() 查看相關信息,發現 xdebug 插件並未激活——在 phpinfo() 頁面看不到 xdebug 的相關信息。
實際上已經在xdebug官網下載了對應版本的dll文件(如下圖所示),且在 php.ini 文件中設置了 xdebug 相關dll文件的關聯。
[PHP_XDEBUG]
zend_extension = "C:\Program Files\php-7.2.26-nts-Win32-VC15-x64\ext\php_xdebug-2.9.0-7.2-vc15-x86_64.dll"
執行 php.exe 后出現錯誤提示:
Failed loading C:\Program Files\php-7.2.26-nts-Win32-VC15-x64\ext\php_xdebug-2.9.0-7.2-vc15-x86_64.dll
1 原因
所加載的 xdebug dll 文件與 PHP 版本不匹配。PHP 是 nts 版本,而不小心下載的 dll 文件是 ts 版本。
TS and NTS
TS refers to multithread capable builds. NTS refers to single thread only builds. Use case for TS binaries involves interaction with a multithreaded SAPI and PHP loaded as a module into a web server. For NTS binaries the widespread use case is interaction with a web server through the FastCGI protocol, utilizing no multithreading (but also for example CLI).
如果不能直接發現此原因,可以將 phpinfo() 頁面的文本復制粘貼至 https://xdebug.org/wizard ,並查看頁面分析報告,如下圖所示。
2 解決方法
下載相應 dll 並按說明配置,重啟服務器后,即可在 phpinfo() 頁面看到 xdebug 已激活。