Top 100 Fastest Servers
#!/usr/local/php/bin/php
<?php
error_reporting(0);
$page_html = file_get_contents('https://github.com/justjavac/Google-IPs');
$regex = '/target="_blank">(\d*?\.\d*?\.\d*?\.\d*?)<\/a>/';
preg_match_all($regex, $page_html, $matches);
$array = array();
foreach($matches[1] as $ip){
list($msec, $sec) = explode(' ', microtime());
$start = (float)$sec + (float)$msec;
$opts = array(
'http' => array(
'method' => "GET",
'timeout' => 2,
'header' => "Accept-language: zh-CN,zh;q=0.8,en;q=0.6,ja;q=0.4,zh-TW;q=0.2\r\n" .
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n" .
"Cache-Control: max-age=0\r\n" .
"User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.149 Safari/537.36\r\n" .
"Accept-Encoding: deflate,sdch\r\n" .
"Host: {$ip}\n\n" .
"Connection: keep-alive\r\n"
)
);
$context = stream_context_create($opts);
$html = file_get_contents("http://{$ip}/search?q=php", false, $context);
if ($html === false) {
echo "IP: {$ip} timeout.\n";
continue;
}
if (preg_match('/<div id="sfcnt">/', $html) === 0) {
echo "IP: {$ip} content error.\n";
continue;
}
list($msec, $sec) = explode(' ', microtime());
$end = (float)$sec + (float)$msec;
$duration = $end - $start;
echo "IP: {$ip} {$duration}s.\n";
$array[$ip] = $duration;
}
asort($array);
$new_array = array_slice($array, 0, 100);
echo "\n------------------------------------------------------\n";
echo " Top 100 Fastest Servers";
echo "------------------------------------------------------\n\n";
foreach($new_array as $key=>$value){
echo $key . "\r\n";
}
?>