<?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.返回格式修改为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"}]
1
fcicq 2016-06-04 00:12:26 +08:00
那套是负载均衡的. 偶尔可能有不均衡的情况, 以运营商的 scale 你一个人用写死一个 IP 也没事.
|