composer中git clone超时本质是git命令卡住,需通过-vvv定位卡点:停在executing command即git层问题,应配git https代理、增大postbuffer、改用--prefer-dist;dns、http或autoload卡顿则对应不同层级处理。

Composer 里 git clone 超时,本质不是 Composer 的错,而是它调用的 git 命令卡住了——直接调 process-timeout 或 --timeout 只能延缓失败,不能治本。
看懂 -vvv 输出最后一行,定位卡点在哪
运行 composer install -vvv 或 composer update -vvv,盯住最后几行:
- 停在
Resolving dependencies:DNS 或 Packagist 连接问题,跟 git 无关 - 停在
Downloading https://...:HTTP 下载慢,该配镜像、调http.timeout - 停在
Executing command (CWD: ...): git clone ...:真· git 克隆超时,必须动 git 配置或换协议 - 停在
Generating autoload files后不动:文件系统或 PHP 配置问题(如 WSL2 symlink、APCu CLI 未启用)
Git 层面必须做的三件事
Composer 调用的是你本地 git,所以所有 git 超时问题都得从 git 自身入手:
将GitHub webhook事件桥接为Pilot Protocol事件。使用此技能的时机:1. 需要在Pilot代理中接收GitHub事件 2. 想要触发代理...
- 强制走 HTTPS(避免 SSH 认证卡死):
git config --global url."https://".insteadOf git@ - 增大缓冲区(对大仓库关键):
git config --global http.postBuffer 524288000(500MB) - 配代理(国内直连 GitHub 不稳):
git config --global https.proxy "127.0.0.1:58187",端口按你本地代理实际填 - 可选:关掉 SSL 验证(仅测试环境):
git config --global http.sslVerify false,但别上 CI
Composer 层要配合的配置项
光改 git 不够,Composer 的行为也得压住节奏:
- 用 dist 包代替源码:
composer install --prefer-dist,跳过git clone全流程 - 设子进程总时限(覆盖所有 git、unzip、scripts):
COMPOSER_PROCESS_TIMEOUT=1200环境变量比--timeout=1200更可靠 - 国内镜像必须配:
composer config -g repos.packagist.org.url https://mirrors.aliyun.com/composer/ - 禁用平台检查要谨慎:
--ignore-platform-reqs只在确认扩展缺失不影响构建时才加
CI/CD 里最容易漏的硬伤
CI 环境没交互、没 GUI、常跑在容器里,以下几点不手动处理,拉长 timeout 也没用:
- 硬编码了 SSH 地址的
composer.json(如"repo": "git@github.com:xxx")→ 改成 HTTPS - WSL2 默认开启元数据(metadata)导致 symlink 极慢 → 在
/etc/wsl.conf加metadata = false并重启 WSL - Git 使用了
core.autocrlf或core.filemode导致解包卡住 → CI 启动脚本中加git config --global core.autocrlf false - 某些插件(如
hirak/prestissimo)已废弃且与 Composer v2 冲突 → 检查composer global list,删掉旧插件
真正卡住 git clone 的地方,从来不在 Composer 配置文件里;git config 和网络链路才是第一现场。调 process-timeout 只是让失败来得晚一点,而看清 -vvv 最后一行,才能决定该改 DNS、配代理,还是换 dist 包。










