卡在Resolving dependencies是DNS问题,需验证DNS(如dig packagist.org)、换公共DNS、检查hosts文件、用热点直连;卡在Downloading https://才调http.timeout(建议600~1200秒);卡在Executing command则调process-timeout。

超时错误不是单一参数能“一键消除”的问题,必须先定位卡在哪一层——Resolving dependencies 是 DNS 问题,Downloading https:// 是 HTTP 超时,Executing command 是子进程超时,三者互不重叠,调错参数等于白等。
卡在 Resolving dependencies 怎么办
这阶段根本不发 HTTP 请求,只做 DNS 查询,http.timeout 和 process-timeout 完全无效。常见于企业网屏蔽、DNS 污染或 hosts 误配。
- 运行
dig mirrors.aliyun.com @114.114.114.114,看是否返回 IPv4 地址;无响应就换 DNS - 检查
/etc/hosts(Linux/macOS)或C:\Windows\System32\drivers\etc\hosts(Windows),确认没把镜像域名指向127.0.0.1 - 用手机热点直连测试一次——很多公司防火墙会拦截
packagist.org和github.com域名 - 临时改 DNS:Linux/macOS 执行
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf;Windows 在网络适配器里手动设置
卡在 Downloading https:// 该调哪个参数
这是 HTTPS 下载阶段卡住,典型错误是 cURL error 28 或 failed to open stream: Connection timed out,只受 http.timeout 控制,和 process-timeout 无关。
-
http.timeout控制单次请求全周期:DNS 解析 + TLS 握手 + 首字节等待 + body 下载,单位秒,默认仅 300(5 分钟) - 国内弱网或拉大 ZIP 包(如 Laravel dist)时,建议设为
600~1200 - 全局生效:
composer config -g http.timeout 600;项目级更稳妥:"config": {"http-timeout": 600}写进composer.json - 注意:
php -i | grep default_socket_timeout查出的值必须 ≥ 你设的http.timeout,否则底层 socket 会在 60 秒就掐断连接 - 别写
config.timeout——这是废弃字段,Composer 早就不读了
卡在 Executing command(比如 git clone)怎么办
这类操作走的是系统命令(git clone、unzip、php -r),http.timeout 完全不生效,唯一有效的是 process-timeout。
-
process-timeout控制外部命令最大执行时间,默认 300 秒,对私有 Git 仓库、大包解压、post-install-cmd 脚本都起作用 - 全局永久生效:
composer config -g process-timeout 1800 - 临时覆盖优先级最高:
COMPOSER_PROCESS_TIMEOUT=2000 composer install - CI 环境推荐环境变量方式,它能覆盖插件和自定义 installer 启动的所有子进程
- 设为
0表示禁用超时,但不推荐长期使用——网络卡死时会无限挂起
为什么调了 timeout 还失败?几个硬坑
最常被忽略的不是参数没设对,而是底层约束没同步调整,或者根本不是超时问题。
-
php -r "echo ini_get('memory_limit');"查内存,update阶段建议 ≥ 1.5G;process-timeout=0 后仍失败,大概率是内存爆了 - 私有 Git 仓库每次
git checkout都计入process-timeout总耗时,不是独立计时——所以 20 个私有包,每个卡 10 秒,300 秒就满了 - 镜像配置漏写
type=composer、URL 少末尾/、键名写成repos.packagist(应为repo.packagist),都会静默失效,但 Composer 不报错 - Docker 容器里被外层
timeout 600 composer install或--stop-timeout包裹,那是另一层中断,Composer 根本感知不到 - GitHub API 限流报 403 或静默卡住,换镜像完全无效——必须配
github-oauth.github.comToken











