直接换阿里云或清华镜像源并清缓存可解决90%超时问题;卡在Resolving dependencies是DNS问题,需检查/更换DNS而非调http.timeout;卡在Downloading才需配置镜像和超时;务必验证镜像是否生效且末尾带斜杠。

直接换阿里云或清华镜像源,再清缓存,90% 的超时问题当场消失;别先调 http.timeout 或代理——那是在网络不通时强行等更久。
卡在 Resolving dependencies 是 DNS 问题,不是超时设置能救的
这一步 Composer 只做域名解析(比如查 mirrors.aliyun.com 的 IP),不走 HTTP、不读代理、不认 http.timeout。你改再多配置都没用。
- 运行
dig mirrors.aliyun.com @114.114.114.114,看是否返回有效 IPv4 地址;若超时或无响应,说明本地 DNS 被污染或不可用 - 临时换 DNS:Linux/macOS 编辑
/etc/resolv.conf加一行nameserver 8.8.8.8;Windows 在网络适配器里手动设 - 检查
/etc/hosts(或C:\Windows\System32\drivers\etc\hosts)是否误把mirrors.aliyun.com指向了127.0.0.1或错误 IP - 用手机热点试一次——很多企业网会屏蔽
packagist.org和 GitHub 域名,但热点通常直连通畅
卡在 Downloading https:// 才该动 http.timeout 和镜像源
只有到这一步,Composer 才真正发起 HTTP 请求,http.timeout 和镜像配置才起作用。但注意:镜像配置写错会静默失效,必须严格校验。
- 换源命令必须完整准确:
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/(末尾斜杠 ✅,少一个就 404) - 验证是否生效:
composer config -g repo.packagist输出必须是完整 JSON,如{"type": "composer", "url": "https://mirrors.aliyun.com/composer/"} - 换源后必须执行
composer clear-cache,否则旧缓存仍会复用失败地址 - 延长超时(仅对这阶段有效):
composer config -g http.timeout 600(单位秒),同时确认 PHP 的default_socket_timeout不低于此值(php -i | grep default_socket_timeout)
卡在 Cloning 或 Executing command 是 process-timeout 或 Git 层问题
这类卡住和 HTTP 下载无关,http.timeout 完全无效。常见于私有包走 git@ 协议、或 post-install-cmd 脚本执行慢。
-
The process "" exceeded the timeout错误只认process-timeout:composer config -g process-timeout 1800 - Git 克隆超时需单独配:
git config --global core.sshCommand "ssh -o ConnectTimeout=15" - 强制跳过 git、改用 zip 下载(对 GitHub 包有效):
composer config -g github-protocols https - 项目级硬写了
repositories字段?它优先级高于全局镜像,会直接忽略repo.packagist配置
最隐蔽的坑是 IPv6 fallback:Composer 默认先试 IPv6 地址,超时(1–3 秒)再退到 IPv4,上百个包叠加就是几分钟“卡住但不报错”。验证方法:curl -v https://packagist.org 2>&1 | grep "Connected to",看到 IPv6 地址且后续卡住,基本就是它。这时候换镜像+清缓存比调 timeout 管用十倍。


















