解决win10 composer xdebug 冲突
背景介绍
开发环境:win10 、php 7.1.7 、composer 1.4.2 、Xdebug 2.5.5
由于 php 开启了 Xdebug 扩展,导致了 composer 命令无效,即 cmd 下输入 composer 命令无任何提示,也无报错(返回为空)。
官方解决办法
To improve performance when the xdebug extension is enabled, Composer automatically restarts PHP without it. You can override this behavior by using an environment variable: [ COMPOSER_ALLOW_XDEBUG=1 ].
Composer will always show a warning if xdebug is being used, but you can override this with an environment variable: [ COMPOSER_DISABLE_XDEBUG_WARN=1 ]. If you see this warning unexpectedly, then the restart process has failed: please report this issue.
—— 官方
也就是添加系统环境变量
COMPOSER_ALLOW_XDEBUG = 1
使composer 以自动重启 php 的方式加载 xdebug。
但是加载xdebug会造成composer 运行缓慢,并且会显示警告。
隐藏警告可以设置环境变量:
COMPOSER_DISABLE_XDEBUG_WARN = 1
推荐解决办法
自定义 php.ini 的方式启动 composer
- 复制 php.ini 为 php.ini-composer
- 删除 php.ini-composer 文件有关 xdebug 的内容
- 编辑 composer.bat
文件默认在 C:\ProgramData\ComposerSetup\bin 目录下
//编辑前
@echo OFF
:: in case DelayedExpansion is on and a path contains !
setlocal DISABLEDELAYEDEXPANSION
php "%~dp0composer.phar" %*
//编辑后
@echo OFF
:: in case DelayedExpansion is on and a path contains !
setlocal DISABLEDELAYEDEXPANSION
php -c php.ini-composer "%~dp0composer.phar" %*
保存后输入 composer 命令,又出现熟悉的界面了,关键是不影响composer速度