Skip to content

Instantly share code, notes, and snippets.

@ninetian
Created August 3, 2016 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninetian/b11d37891d9a815e4af26e9010469811 to your computer and use it in GitHub Desktop.
Save ninetian/b11d37891d9a815e4af26e9010469811 to your computer and use it in GitHub Desktop.
CDCDCD
<?php
error_reporting(0);
header("Content-Type: application/json;charset=utf-8");
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Connection: close");
$url = isset($_GET['url']) ? $_GET['url'] : die('miss url');
//墙内的 Cache Servers IP List
$rlist = array(
"120.52.72.19",
//"120.52.72.20",
"120.52.72.21",
"120.52.72.22",
"120.52.72.23",
"120.52.72.24",
"120.52.72.47",
"120.52.72.48",
"120.52.72.52",
"120.52.72.53",
"120.52.72.54",
"120.52.72.55",
"120.52.72.56",
"120.52.72.58",
"120.52.72.59",
);
$domain = parseurl($rlist[rand(0, count($rlist) - 1)]) .'/'.$url;
$data = array();
$data['head'] = get_header($domain);
$data['data'] = get_full($domain);
echo json_encode($data);
function get_header($link) {
$main = array();
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $link);
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_NOBODY, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_NETRC, 1); // omit if you know no urls are FTP links...
curl_setopt ($ch, CURLOPT_TIMEOUT, 300);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
ob_start();
curl_exec ($ch);
$stuff = ob_get_contents();
ob_end_clean();
curl_close ($ch);
return $stuff;
}
function get_full($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$data = curl_exec($ch);
if(!curl_errno($ch)) {
$info = curl_getinfo($ch);
$array = array(
"status" => "OK",
"msg" => '',
//"url" => $info['url'],
"status_code" => $info['http_code'],
"header_size" => $info['header_size'],
"request_size" => $info['request_size'],
"total_time" => $info['total_time'],
"namelookup_time" => $info['namelookup_time'],
"connect_time" => $info['connect_time'],
"pretransfer_time" => $info['pretransfer_time'],
"size_upload" => $info['size_upload'],
"size_download" => $info['size_download'],
"speed_download" => $info['speed_download'],
"speed_upload" => $info['speed_upload'],
"download_content_length" => $info['download_content_length'],
"upload_content_length" => $info['upload_content_length'],
"starttransfer_time" => $info['starttransfer_time'],
"redirect_time" => $info['redirect_time'],
"redirect_url" => $info['redirect_url']
);
//echo json_encode($array);
} else {
$array = array("status" => "ERROR",'msg'=>curl_error($ch) );
}
return $array;
curl_close($ch);
}
function parseurl($url, $scheme = 'http://') {
return parse_url($url, PHP_URL_SCHEME) === null ? $scheme . $url : $url;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment