npm install卡住时,若卡在resolving dependencies是dns问题,需手动测dns、换系统dns或检查hosts;若卡在downloading才是http超时,应调高http.timeout并换国内镜像源https://registry.npmmirror.com。

直接调高 http.timeout 和 process-timeout 并换国内镜像源,90% 的“超时”问题当场解决;但若卡在 Resolving dependencies,改 timeout 完全无效——那是 DNS 问题,不是网络慢。
卡在 Resolving dependencies 是 DNS 问题,不是 timeout 能解决的
这一步根本没发 HTTP 请求,Composer 只在查 mirrors.aliyun.com 或 packagist.org 的 IP 地址。改 http.timeout 白等,错误里常带 Could not resolve host 或 unknown host。
- 先手动测 DNS:运行
dig mirrors.aliyun.com @8.8.8.8,看是否返回有效 IP - 临时换系统 DNS:Linux/macOS 改
/etc/resolv.conf加nameserver 8.8.8.8;Windows 在网络适配器里设 - 检查
/etc/hosts(或C:\Windows\System32\drivers\etc\hosts)是否误写了错误的域名映射 - 用手机热点试一次——很多企业网会屏蔽
packagist.org和github.com,但热点通常通
卡在 Downloading https:// 才该调 http.timeout
这才是真正的 HTTP 层超时,http.timeout 控制 DNS 解析 + TLS 握手 + 首字节等待 + 整个 body 传输,默认仅 60 秒,对国内镜像或大包明显不够。
围绕关键发现、作用机制、临床相关性及研究局限性展开讨论。适用于撰写或优化任何生物医学论文的“讨论(Discussion)”部分——包括结果解读、与既往文献关联、阐释意外发现、界定研究局限性,以及撰写结论。当用户输入以下任一指令时也会自动触发该功能: - “write my discussion” - “help me discuss my findings” - “how do I compare to prior studies” - “write the limitations par
- 全局设置(推荐):
composer config -g http.timeout 600 - 项目级更稳妥(CI 友好):在
composer.json的"config"段加"http.timeout": 600 - 临时调试优先用环境变量:
COMPOSER_HTTP_TIMEOUT=1200 composer install,避免污染配置 - 注意:
php -i | grep default_socket_timeout查 PHP 底层值,若低于你设的http.timeout,会提前掐断连接——常见是 60,务必同步调高
报 The process timed out 或卡在 Executing command 要调 process-timeout
这是子进程执行太久被杀,比如 git clone、unzip、跑 post-install-cmd 脚本,错误里一定含 [RuntimeException] The process "" exceeded the timeout,和 HTTP 完全无关。
- 全局改:
composer config -g process-timeout 1800(30 分钟) - 项目级改:直接在
composer.json顶层加"config": {"process-timeout": 1200} - CI 环境建议用环境变量兜底:
COMPOSER_PROCESS_TIMEOUT=2000,某些 Composer 版本对它更敏感 - 设为 0 表示不限时,但不推荐——万一远程 Git 仓库彻底不可达,会无限挂起
换镜像源必须写对命令,漏一个字符就静默失败
composer config -g repo.packagist 静默失败率极高——不报错,但配置根本没写进 ~/.composer/config.json。必须同时满足三个硬性条件:
- 键名严格为单数
repo.packagist(写成repos.packagist或repositories.packagist.org都无效) - 命令中间的
composer是 type 值,不能省略,也不能替换成 URL - URL 必须以
https://开头,且末尾带/:https://mirrors.aliyun.com/composer/✅,https://mirrors.aliyun.com/composer❌(会拼出/composer/packages.json,直接 404) - 验证是否真生效:
composer config -g repo.packagist输出必须是完整 JSON,例如{"type": "composer", "url": "https://mirrors.aliyun.com/composer/"};如果只是字符串、null、空值,或还是https://packagist.org,说明没配对
最常被忽略的一点:项目级 repositories 字段会完全屏蔽全局镜像配置,哪怕你 composer config -g repo.packagist 写得再对,只要 composer.json 里有 "repositories" 数组,它就优先读那个——检查用 composer config repositories,空才安全。










