1

PHP开发的Github文件下载加速项目

 3 years ago
source link: https://tlanyan.me/php-version-ghproxy/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

起因

国内下载Github的代码或文件比较困难,或者感人的几KB,或者无法下载。如果服务器上的项目构建依赖于Github代码,必须采取加速手段以节省时间。

一种方法是采用代理/VPN加速,例如使用 ssh -D 建立动态代理,然后配合 proxychains 让应用走代理加速;另一种方法是直接加速要下载的资源。第一种方法需要在服务器上部署代理环境,对新手不友好。第二种加速链接可以写在脚本中,适合多人都要部署环境的情形。

加速Github资源,最初接触到的是 部署在Cloudflare workers上的js版本 。经过本人测试,发现在国内VPS上速度非常不理想,于是想到用自己买的好线路VPS来加速。

作者提供了Python版(以及docker版),但作为一个PHP开发,为何不用PHP编写的呢?于是顺手写了一个,目前开源在Github上: https://github.com/tlanyan/ghproxy

Github文件下载加速项目说明

基于异步PHP框架 ReactPHP 开发,演示网址: https://gh.2i.gs

使用方式: https://gh.2i.gs/要加速的github网址 ,例如要加速本项目代码下载,使用网址 https://gh.2i.gs/https://github.com/tlanyan/ghproxy/archive/main.zip 即可加速下载。也可在演示网站输入资源URL,点击下载按钮查看跳转后的加速网址。

目前项目(仅)支持如下形式资源的加速:

分支源码:https://github.com/tlanyan/ghproxy/archive/main.zip

release源码:https://github.com/tlanyan/yii2/archive/2.0.4.zip

release文件:https://github.com/tlanyan/yii2/archive/2.0.4.zip

分支文件:https://github.com/tlanyan/ghproxy/blob/main/index.html

API请求:https://api.github.com/repos/reactphp/http/releases/latest

简单来说,在Github网站上右键复制出来的链接都是符合标准的。其中默认release、archive直接反代加速,文件会跳转至JsDelivr或cnpmjs.org加速下载。

注意:

  1. 不支持加速项目文件夹
  2. 本项目支持加速API请求(但是API请求一般数据很小,能直接访问的情况下没有加速效果)
  3. 网站仅做演示,可靠使用请自行部署

其他事项

1. 详细部署教程请参考 项目主页说明 ,本文不再赘述。

2. 后来本人上网搜索,发现了许多加速Github的方式,包括使用cnpm.js等镜像站,或者用 Ucloud 提供的GlobalSSH等骚操作,详情参考: 让你的GitHub下载飞速提升到2M/s以上

参考

  1. 开源分享:gh-proxy——基于cloudflare workers的GitHub文件加速
  2. 让你的GitHub下载飞速提升到2M/s以上

AD: 【国外VPS推荐】 搬瓦工三网回程CN2 GIA VPS,季付46.87$


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK