V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
weakiwi
V2EX  ›  问与答

联通缓存服务器测速脚本(php)

  •  1
     
  •   weakiwi · 2016-06-04 00:02:48 +08:00 · 2117 次点击
    这是一个创建于 3102 天前的主题,其中的信息可能已经有所发展或是发生改变。
    <?php
        error_reporting(0);
        for($idx=1;$idx<255;$idx++){
            $url = "http://120.52.72." . (string)$idx . "/www.hi-pda.com/forum/templates/colors/images/logo.gif";
            $stime=microtime(true);
            $result_code = file_get_contents($url);
            $etime=microtime(true);
            if($result_code != false){
                $distance = $etime - $stime;
                echo "120.52.72.$idx ". "time: $distance\n";
            }
        }
    ?>
    

    过段时间把返回改成 json 的,请求改成并发的

    第 1 条附言  ·  2016-06-04 09:56:58 +08:00

    github连接在此

    新增:

    1.返回格式修改为json

    2.默认按响应时间由快到慢排序

    3.采用并发,提升速度

    [{"total_time":0.295325,"download_speed":16415,"host_name":"120.52.72.54"},{"total_time":0.296764,"download_speed":16336,"host_name":"120.52.72.20"},{"total_time":0.297254,"download_speed":16309,"host_name":"120.52.72.19"},{"total_time":0.29768,"download_speed":16285,"host_name":"120.52.72.47"},{"total_time":0.297697,"download_speed":16285,"host_name":"120.52.72.56"},{"total_time":0.30002,"download_speed":16158,"host_name":"120.52.72.55"},{"total_time":0.300302,"download_speed":16143,"host_name":"120.52.72.23"},{"total_time":0.300889,"download_speed":16112,"host_name":"120.52.72.53"},{"total_time":0.305419,"download_speed":15873,"host_name":"120.52.72.59"},{"total_time":0.305443,"download_speed":15872,"host_name":"120.52.72.24"},{"total_time":0.305734,"download_speed":15856,"host_name":"120.52.72.21"},{"total_time":0.306264,"download_speed":15829,"host_name":"120.52.72.52"},{"total_time":0.30752,"download_speed":15764,"host_name":"120.52.72.48"},{"total_time":0.31431,"download_speed":15424,"host_name":"120.52.72.58"},{"total_time":0.416933,"download_speed":7140,"host_name":"120.52.72.81"}]
    
    第 2 条附言  ·  2016-06-04 14:40:06 +08:00
    通过 chrome 的插件 modify header
    新增一条规则:
    mod->host->缓存服务器的 ip
    这样访问所有网站都是可以通过缓存服务器了。当然主要是为了下东西方便咯
    1 条回复    2016-06-04 00:12:26 +08:00
    fcicq
        1
    fcicq  
       2016-06-04 00:12:26 +08:00
    那套是负载均衡的. 偶尔可能有不均衡的情况, 以运营商的 scale 你一个人用写死一个 IP 也没事.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1561 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 17:06 · PVG 01:06 · LAX 09:06 · JFK 12:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.