卡在Resolving dependencies是DNS解析问题,需用dig验证并更换DNS或修改hosts;卡在Downloading才调http.timeout和镜像源;卡在Executing command则需调整process-timeout。

卡在 Resolving dependencies 是 DNS 问题,不是镜像能解决的
这一步根本没发 HTTP 请求,只是查 mirrors.aliyun.com 这类域名的 IP 地址。换镜像、调 http.timeout 完全无效。
必须验证 DNS 是否通:
- 运行
dig mirrors.aliyun.com @8.8.8.8,看是否返回 IPv4 地址;若超时或无响应,说明本地 DNS 被污染 - 临时改 DNS:Linux/macOS 编辑
/etc/resolv.conf加nameserver 8.8.8.8;Windows 在网络适配器里手动设 - 检查
/etc/hosts(或C:\Windows\System32\drivers\etc\hosts)是否把镜像域名指向了127.0.0.1或错误 IP - 用手机热点试一次——很多企业网会拦截
packagist.org和 GitHub 域名,但热点通常直连
卡在 Downloading 才该换镜像 + 调 http.timeout
只有到这步才真正发起 HTTP 请求,此时镜像源和超时配置才起作用。
操作要点:
- 设阿里云镜像:
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/(末尾斜杠不能少) - 验证是否生效:
composer config -g repo.packagist输出必须是完整 JSON,比如{"type": "composer", "url": "https://mirrors.aliyun.com/composer/"} - 全局延长单次 HTTP 超时:
composer config -g http.timeout 600(单位秒,600 = 10 分钟) - 换源后必须执行
composer clear-cache,否则旧缓存仍会复用失败地址
卡在 Executing command 说明 process-timeout 太短
这步涉及 git clone、unzip、post-install-cmd 等子进程,由 process-timeout 控制,默认仅 300 秒,和 HTTP 请求无关。
常见应对方式:
- 临时绕过:
composer install --process-timeout=0(禁用)或--process-timeout=1200(20 分钟) - 永久生效:
composer config -g process-timeout 1200 - 若已设为 0 仍失败,大概率是内存不足——检查 PHP
memory_limit是否 ≥ 1.5G,尤其update解析锁文件阶段 - 禁用 packagist.org 回源防 fallback 拖慢:
composer config -g repo.packagist false
镜像还原不了的问题:Git 包绕过镜像直连 GitHub
当依赖中含 "type": "git"(如开发版包),Composer 会跳过镜像,直接调系统 git clone,此时 DNS、代理、SSH 配置都得单独处理。
关键动作:
- 强制 Git 走 HTTPS:
composer config -g github-protocols https - 给 Git 加超时(Linux/macOS):
git config --global core.sshCommand "timeout 300 ssh" - 确保
http.proxy和https.proxy已配好,否则 Git 无法穿透代理 - CI 中加
--prefer-dist强制走 zip 包,避免触发 git clone
镜像只是加速下载的一环,DNS、Git 行为、子进程限制、PHP 内存这些环节任何一个卡住,都会让“还原镜像”变成无效操作。


















