您的浏览器过于古老 & 陈旧。为了更好的访问体验, 请 升级你的浏览器
一位不愿透露姓名的用户 发布于2020年10月11日 21:17 最近更新于 2020年10月11日 22:01

VSCode 配置集成 PHP IntelliSense 时报错:Error spawning PHP: Command failed: php --version

44 次浏览 读完需要≈ 12 分钟 PHPVS Code

我使用 VS Code 进行PHP开发,安装了 PHP IntelliSense 扩展插件,并按照VSCode官方文档的指引设置了PHP的相关参数。

我在 VSCode 的配置文件settings.json中,进行了如下的配置:

{
	"php.executablePath": "E:/xampp/php/php.exe",
	"php.validate.enable": true,
	"php.validate.executablePath": "E:/xampp/php/php.exe",
}

路径配置都是对的,但是在 VSCode 中打开PHP文件时,软件右下角还是提示如下信息:

Error spawning PHP: Command failed: E:/xampp/php/php.exe --version
PHP Warning:  PHP Startup: Unable to load dynamic library 'bz2' (tried: \xampp\php\ext\bz2 (找不到指定的模块。), \xampp\php\ext\php_bz2.dll (找不到指定的模块。)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'curl' (tried: \xampp\php\ext\curl (找不到指定的模块。), \xampp\php\ext\php_curl.dll (找不到指定的模块。)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'fileinfo' (tried: \xampp\php\ext\fileinfo (找不到指定的模块。), \xampp\php\ext\php_fileinfo.dll (找不到指定的模块。)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'gd2' (tried: \xampp\php\ext\gd2 (找不到指定的模块。), \xampp\php\ext\php_gd2.dll (找不到指定的模块。)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'gettext' (tried: \xampp\php\ext\gettext (找不到指定的模块。), \xampp\php\ext\php_gettext.dll (找不到指定的模块。)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'mbstring' (tried: \xampp\php\ext\mbstring (找不到指定的模块。), \xampp\php\ext\php_mbstring.dll (找不到指定的模块。)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'exif' (tried: \xampp\php\ext\exif (找不到指定的模块。), \xampp\php\ext\php_exif.dll (找不到指定的模块。)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'mysqli' (tried: \xampp\php\ext\mysqli (找不到指定的模块。), \xampp\php\ext\php_mysqli.dll (找不到指定的模块。)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: \xampp\php\ext\pdo_mysql (找不到指定的模块。), \xampp\php\ext\php_pdo_mysql.dll (找不到指定的模块。)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_sqlite' (tried: \xampp\php\ext\pdo_sqlite (找不到指定的模块。), \xampp\php\ext\php_pdo_sqlite.dll (找不到指定的模块。)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'php_openssl.dll' (tried: \xampp\php\ext\php_openssl.dll (找不到指定的模块。), \xampp\php\ext\php_php_openssl.dll.dll (找不到指定的模块。)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'php_ftp.dll' (tried: \xampp\php\ext\php_ftp.dll (找不到指定的模块。), \xampp\php\ext\php_php_ftp.dll.dll (找不到指定的模块。)) in Unknown on line 0
PHP Warning:  Cannot open '/xampp/php/extras/browscap.ini' for reading in Unknown on line 0
PHP Fatal error:  Unable to start standard module in Unknown on line 0


Warning: PHP Startup: Unable to load dynamic library 'bz2' (tried: \xampp\php\ext\bz2 (找不到指定的模块。), \xampp\php\ext\php_bz2.dll (找不到指定的模块。)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'curl' (tried: \xampp\php\ext\curl (找不到指定的模块。), \xampp\php\ext\php_curl.dll (找不到指定的模块。)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'fileinfo' (tried: \xampp\php\ext\fileinfo (找不到指定的模块。), \xampp\php\ext\php_fileinfo.dll (找不到指定的模块。)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'gd2' (tried: \xampp\php\ext\gd2 (找不到指定的模块。), \xampp\php\ext\php_gd2.dll (找不到指定的模块。)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'gettext' (tried: \xampp\php\ext\gettext (找不到指定的模块。), \xampp\php\ext\php_gettext.dll (找不到指定的模块。)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'mbstring' (tried: \xampp\php\ext\mbstring (找不到指定的模块。), \xampp\php\ext\php_mbstring.dll (找不到指定的模块。)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'exif' (tried: \xampp\php\ext\exif (找不到指定的模块。), \xampp\php\ext\php_exif.dll (找不到指定的模块。)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'mysqli' (tried: \xampp\php\ext\mysqli (找不到指定的模块。), \xampp\php\ext\php_mysqli.dll (找不到指定的模块。)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: \xampp\php\ext\pdo_mysql (找不到指定的模块。), \xampp\php\ext\php_pdo_mysql.dll (找不到指定的模块。)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'pdo_sqlite' (tried: \xampp\php\ext\pdo_sqlite (找不到指定的模块。), \xampp\php\ext\php_pdo_sqlite.dll (找不到指定的模块。)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'php_openssl.dll' (tried: \xampp\php\ext\php_openssl.dll (找不到指定的模块。), \xampp\php\ext\php_php_openssl.dll.dll (找不到指定的模块。)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'php_ftp.dll' (tried: \xampp\php\ext\php_ftp.dll (找不到指定的模块。), \xampp\php\ext\php_php_ftp.dll.dll (找不到指定的模块。)) in Unknown on line 0

Warning: Cannot open '/xampp/php/extras/browscap.ini' for reading in Unknown on line 0

Fatal error: Unable to start standard module in Unknown on line 0

请问,这种问题该如何解决呢?

1 个回答

Ready · 13天前

根据你给出的错误提示信息,归纳一下,其实就是下面两个错误:

Unable to load dynamic library 'bz2' (tried: \xampp\php\ext\bz2 (找不到指定的模块。), \xampp\php\ext\php_bz2.dll (找不到指定的模块。)) in Unknown on line 0
Cannot open '/xampp/php/extras/browscap.ini' for reading in Unknown on line 0

究其本质,这两个错误其实是同一个错误,就是php.exe无法按照PHP配置文件(php.ini)中指定的路径找到对应的扩展模块和其他配置文件(这里是browscap.ini)。

看得出,你用的就是XAMPP

这是因为XAMPP中PHP配置文件(php.ini)的许多路径配置都是相对路径,相对的是当前磁盘的根目录:

; 以下是配置的片段
[PHP]
extension_dir = "\xampp\php\ext"

[browscap]
browscap = "\xampp\php\extras\browscap.ini"

你的VSCode安装目录应该不在E盘,所以它执行php.exe时,根目录相对的当前磁盘不是你的XAMPP所在的E盘,自然就无法正确找到对应的文件。

你可以将上述相对路径配置修改为绝对路径,如以下配置所示:

; 以下是配置的片段
[PHP]
extension_dir = "E:\xampp\php\ext"

[browscap]
browscap = "E:\xampp\php\extras\browscap.ini"
已采纳 ? 0 0 0 编辑

撰写答案