配 github personal access token(classic 类型且含 repo 权限)并正确设置 composer config --global github-oauth.github.com ,同时确保 auth.json 权限为 600(linux/macos)或非只读(windows),才能突破每小时 60 次的匿名 api 限额。

直接配 GitHub Personal Access Token 就能解决,不配就永远卡在每小时 60 次的匿名限额里——镜像源本身不带认证,也绕不开 GitHub API 元数据请求。
为什么配了镜像还是报 “API rate limit exceeded”
镜像(如阿里云 https://mirrors.aliyun.com/composer/)只缓存 Packagist 的包元数据和 dist 包下载链接,但 Composer 在解析 dev-master、dev-feature/x 分支,或遇到未缓存的 tag、私有 fork、VCS 类型依赖时,仍会直连 api.github.com 查 commit 和 tag 列表。这部分请求不走镜像,且默认无认证。
- 镜像无法代理 GitHub API 请求,只代理 Packagist 接口
-
composer install日志里出现Loading composer repositories with package information后卡住,大概率就是这一步触发了限流 - 即使所有包都来自 Packagist,只要依赖里含
"type": "vcs"或未打 tag 的开发版,就会调 GitHub API
怎么正确配置 GitHub OAuth Token(不是随便生成一个就行)
Token 必须是 classic 类型,且权限不能少——public_repo 不够用,repo 才是必需项;read:packages 只在你用 GitHub Packages 托管私有 PHP 包时才需要。
使用 `gh` CLI 与 GitHub 交互。通过`gh issue`、`gh pr`、`gh run` 和 `gh api` 管理 issue、PR、CI 运行以及高级查询。
- 去
Settings → Developer settings → Personal access tokens → Tokens (classic)创建 - 勾选
repo(必须),read:packages(按需),**不要选delete_repo或admin:org等高危项** - 执行命令:
composer config --global github-oauth.github.com <your_token_here></your_token_here>—— 注意是空格分隔,不是=,host 必须是github.com - Linux/macOS 下立刻执行:
chmod 600 ~/.composer/auth.json;Windows 用户需确认该文件未被系统设为只读 - PowerShell 中粘贴含
$的 token 会被截断,改用 cmd,或加单引号:composer config --global github-oauth.github.com '$TOKEN'
验证 Token 是否真被 Composer 使用
光写进配置不等于生效。Composer 会静默忽略权限错误、JSON 格式错误或 host 名不匹配的配置,此时仍走 60 次限额。
- 运行:
composer config --global --list | grep github-oauth,应输出类似github-oauth.github.com=ghp_abc*** - 加
-v运行一次安装:composer install -v,日志中出现Using GitHub token from configuration才算真正启用 - 手动测 Token 是否有效:
curl -H "Authorization: token <your_token_here>" https://api.github.com/rate_limit</your_token_here>,返回中rate.limit应为5000,不是60 - CI 环境别硬编码 token,用
COMPOSER_AUTH='{"github-oauth":{"github.com":"xxx"}}'注入环境变量
最常被忽略的是 auth.json 文件权限和 host 名拼写——写成 github-oauth.api.github.com 或 github-oauth.www.github.com 都会静默失效;Linux 下权限不是 600,Composer 直接跳过该文件。这些细节不检查,配了也白配。
大量免费API接口:立即使用
涵盖生活服务API、金融科技API、企业工商API、等相关的API接口服务。免费API接口可安全、合规地连接上下游,为数据API应用能力赋能!










