运行 composer diagnostic
时,出现以下错误:
The xdebug extension is loaded, this can slow down Composer a little. Disabling it when using Composer is recommended.
如何仅在运行 Composer 时禁用 xdebug?
最佳答案
更新:对于 Xdebug 3+:
从 Xdebug 3 开始,可以通过将选项 xdebug.mode
设置为 off
或通过设置环境变量 XDEBUG_MODE 来完全禁用 Xdebug =关闭
.
通过别名 composer
可以很容易地为 composer 禁用 Xdebug。
alias composer='XDEBUG_MODE=off \composer'
或
alias composer='php -dxdebug.mode=off $(where composer | fgrep -v composer: | head -1)'
您可以将别名添加到您的 $HOME/.bashrc
以使其永久化。
更新:对于 Xdebug 1.3 - 3.0.0:
该问题已在 Composer 1.3 中得到修复.通过执行 composer self-update
将 composer 更新到最新版本,而不是尝试以下解决方法。
对于 Xdebug < 1.3
这是我对@ezzatron 代码的修改。我已更新脚本以从 phpinfo 输出中检测 ini 文件。
#!/bin/sh
php_no_xdebug () {
temporaryPath="$(mktemp -t php.XXXX).ini"
# Using awk to ensure that files ending without newlines do not lead to configuration error
php -i | grep "\.ini" | grep -o -e '\(/[a-z0-9._-]\+\)\+\.ini' | grep -v xdebug | xargs awk 'FNR==1{print ""}1' | grep -v xdebug > "$temporaryPath"
php -n -c "$temporaryPath" "$@"
rm -f "$temporaryPath"
}
php_no_xdebug /usr/local/bin/composer.phar $@
# On MacOS with composer installed using brew, comment previous line
# Install jq by executing `brew install jq` and uncomment following line.
# php_no_xdebug /usr/local/Cellar/composer/`brew info --json=v1 composer | jq -r '.[0].installed[0].version'`/libexec/composer.phar $@
关于php - 运行 Composer 时禁用 xdebug,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31083195/