{"id":13793147,"url":"https://github.com/zencodex/composer-mirror","last_synced_at":"2025-04-04T15:10:12.344Z","repository":{"id":37583818,"uuid":"188222609","full_name":"zencodex/composer-mirror","owner":"zencodex","description":"Composer 全量镜像发布于2017年3月，曾不间断运行2年多。这个开源有助于理解 Composer 镜像的工作原理","archived":false,"fork":false,"pushed_at":"2023-09-14T04:08:56.000Z","size":199,"stargazers_count":593,"open_issues_count":0,"forks_count":73,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-28T14:08:22.639Z","etag":null,"topics":["composer","flysystem","mirror","packagist","upyun"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zencodex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-05-23T11:41:19.000Z","updated_at":"2025-01-14T09:00:20.000Z","dependencies_parsed_at":"2024-01-20T18:04:04.095Z","dependency_job_id":null,"html_url":"https://github.com/zencodex/composer-mirror","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zencodex%2Fcomposer-mirror","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zencodex%2Fcomposer-mirror/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zencodex%2Fcomposer-mirror/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zencodex%2Fcomposer-mirror/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zencodex","download_url":"https://codeload.github.com/zencodex/composer-mirror/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198463,"owners_count":20900080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composer","flysystem","mirror","packagist","upyun"],"created_at":"2024-08-03T22:01:23.013Z","updated_at":"2025-04-04T15:10:12.319Z","avatar_url":"https://github.com/zencodex.png","language":"PHP","funding_links":[],"categories":["PHP","Composer"],"sub_categories":["PRC"],"readme":"[![stars](https://img.shields.io/github/stars/zencodex/composer-mirror.svg)](https://github.com/zencodex/composer-mirror)\n[![forks](https://img.shields.io/github/forks/zencodex/composer-mirror.svg)](https://github.com/zencodex/composer-mirror)\n[![build](https://img.shields.io/badge/build-passing-brightgreen.svg)](https://github.com/zencodex/composer-mirror)\n[![issues](https://img.shields.io/github/issues/zencodex/composer-mirror.svg)](https://github.com/zencodex/composer-mirror)\n[![MIT](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://github.com/zencodex/composer-mirror)\n\n\u003e 感谢 Laravel China 社区 的 Summer，提出了做镜像的建议，感谢早期参与测试的小伙伴们，给了众多的支持 🙏\n\n\u003e Laravel China 社区镜像，于 2019 年 9 月 4 号停用。详见：https://learnku.com/articles/30758 ，替代镜像请见 Wiki：[Wiki：Composer 国内加速：可用镜像列表](https://learnku.com/composer/wikis/30594)\n\n## ZComposer 镜像的安装部署\n\n推荐运行主机配置：\n\n* [x] 内存最好不低于4G\n* [x] 剩余磁盘空间不低于30G\n\n```sh\n$ apt install beanstalkd\n$ cd composer-mirror\n$ composer install\n```\n\n## 修改配置参数\n\n\u003e 通常根据自己部署的实际环境，修改参数。详细配置说明详见 config.default.php\n\n`cp config.default.php config.php`，修改 config.php 中的如下参数\n\n```php\n    /**\n     * distdir 用于存储 zip 包\n     */\n    'distdir' =\u003e __DIR__ . '/dist/',\n\n    /**\n     * 指向 mirrorUrl 对应的 web 实际目录\n     */\n    'cachedir' =\u003e __DIR__ . '/cache/',\n\n    /**\n     * packagistUrl：官方采集源\n     */\n    'packagistUrl' =\u003e 'https://packagist.org',\n\n    /**\n     * 镜像包发布站点, packages.json 入口根域名\n     */\n    'mirrorUrl' =\u003e 'https://packagist.laravel-china.org',\n\n    /**\n     * .json 中 dist 分发 zip 包的CDN域名\n     */\n    'distUrl' =\u003e 'https://dl.laravel-china.org/',\n```\n\n### supervisor 配置\n\n`sudo vim /etc/supervisor/supervisord.conf`，添加如下配置信息：\n\n    [program:crawler]\n    command=php ./bin/console app:crawler\n    directory=/home/zencodex/composer-mirror/  ;部署代码的位置，自行替换\n    autostart=true\n    autorestart=true\n    redirect_stderr = true  ; 把 stderr 重定向到 stdout，默认 false\n    stdout_logfile_maxbytes = 10MB  ; stdout 日志文件大小，默认 50MB\n    stdout_logfile_backups = 5      ; stdout 日志文件备份数\n    stdout_logfile = /tmp/composer_crawler_stdout.log\n    \n    [program:composer_daemon]\n    command=php ./bin/console app:daemon\n    directory=/home/zencodex/composer-mirror/  ;部署代码的位置，自行替换\n    autostart=true\n    autorestart=true\n    redirect_stderr = true  ; 把 stderr 重定向到 stdout，默认 false\n    stdout_logfile_maxbytes = 10MB  ; stdout 日志文件大小，默认 50MB\n    stdout_logfile_backups = 5      ; stdout 日志文件备份数\n    stdout_logfile = /tmp/composer_daemon_stdout.log\n\n### crontab 定时任务\n\n```\n# sudo crontab -e\n# 根据自己环境代码的位置，替换 /home/zencodex/composer-mirror \n# getcomposer 是获取最新的 composer，上传到 CDN 云存储\n\n0 */2 * * * /usr/bin/php /home/zencodex/composer-mirror/bin/console app:clear --expired=json\n0 1 * * * /usr/bin/php /home/zencodex/composer-mirror/getcomposer.php\n```\n\n## 常用命令\n\n```sh\n# 执行抓取任务\n$ php ./bin/console app:crawler\n\n# 后台多进程模型同步又拍云\n$ php ./bin/console app:daemon\n\n# 清理过期垃圾文件\n$ php ./bin/console app:clear --expired=json\n\n# 扫描并校验所有json和zip文件的hash256\n$ php ./bin/console app:scan\n```\n\n### For Developers\n\n* 没有使用数据库存储，完全是按目录结构存储\n* 每个包的 dist/zip 文件存储的是对应 github url的下载地址，因磁盘空间有限，不在本地存储，直接推送到云端\n* 清理过期文件，判断是否有更新，是否过期的依据是文件的时间戳，所以不要手动对文件做 touch，或引起时间戳变化的操作\n\n\u003e 如果使用非又拍云的其他平台，需要注意以下代码，需要自行实现\n\n* ClientHandlerPlugin 需要 Flysystem 的对应 Adapter 有对应接口，本例中只有 zencodex/flysystem-upyun 实现了，其他第三方包，可以参照样例自行实现\n* Cloud::refreshRemoteFile，作用是刷新 CDN 缓存的文件，这个每日有调用频率限制，所以只刷新 package.json 时使用\n* Cloud::refreshRemoteFile，如果使用非又拍云的平台，需要替换为自己平台刷新代码。或者参照 `ZenCodex\\Support\\Flysystem\\Adapter\\UpyunAdapter` 封装 getClientHandler。\n* Cloud::prefetchDistFile 和 refreshRemoteFile 类似，调用的是云平台特殊接口，无法统一封装在 Flysystem，所以也通过 getClientHandler 处理 \n\n### 注意最大子目录数的坑\n\n代码详情见 `src/Commands/PatchCommand.php`\n\n```php\n/*\n|--------------------------------------------------------------------------\n| linux ext4 支持的最大子目录数有上限，大约 64000 ~ 65000，目前包的数量已经超过上限\n|--------------------------------------------------------------------------\n|\n| 有三种解决方法，前2种基本不现实。所以自己通过尝试，找到了3 (软连接不计数的方案)\n|\n|   1. 更换没有子文件夹数量限制的文件系统，比如 xfs \n|   2. 或者更改相关代码，重新编译 ext4 内核\n|   3. 切割大的文件夹，分散不同字母开头的文件。在主文件夹里面使用软连接，软连接并不计数\n|\n*/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzencodex%2Fcomposer-mirror","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzencodex%2Fcomposer-mirror","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzencodex%2Fcomposer-mirror/lists"}