淘宝有个 ip地址验证库
http://ip.taobao.com/
我需要把大概文本文件中380W条数据 过下淘宝的api然后把结果存到我自己的数据库里我现在是这样做的,我写了个翻页跳转,每秒读取9条数据,然后跳转到下一页,读取下一个9条数据初步算算的话 42W次左右的跳转才能读取完现在的问题是,每天基本上浏览器都会死掉……这是什么原因导致的?缓存?还是什么?!如何解决呢?
http://ip.taobao.com/
我需要把大概文本文件中380W条数据 过下淘宝的api然后把结果存到我自己的数据库里我现在是这样做的,我写了个翻页跳转,每秒读取9条数据,然后跳转到下一页,读取下一个9条数据初步算算的话 42W次左右的跳转才能读取完现在的问题是,每天基本上浏览器都会死掉……这是什么原因导致的?缓存?还是什么?!如何解决呢?
http://ip.taobao.com/service/getIpInfo.php?ip=122.11.37.53
'122.11.37.53',
'122.11.37.154',
'122.11.137.55',
);
foreach($ips as $ip) print_r(json_decode(file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=$ip")));stdClass Object
(
[code] => 0
[data] => stdClass Object
(
[country] => 中国
[country_id] => CN
[area] => 华北
[area_id] => 100000
[region] => 北京市
[region_id] => 110000
[city] => 北京市
[city_id] => 110100
[county] => 朝阳区
[county_id] => 110105
[isp] => 联通
[isp_id] => 100026
[ip] => 122.11.37.53
))
stdClass Object
(
[code] => 0
[data] => stdClass Object
(
[country] => 中国
[country_id] => CN
[area] => 华北
[area_id] => 100000
[region] => 北京市
[region_id] => 110000
[city] => 北京市
[city_id] => 110100
[county] => 朝阳区
[county_id] => 110105
[isp] => 联通
[isp_id] => 100026
[ip] => 122.11.37.154
))
stdClass Object
(
[code] => 0
[data] => stdClass Object
(
[country] => 新加坡
[country_id] => SG
[area] =>
[area_id] =>
[region] =>
[region_id] =>
[city] =>
[city_id] =>
[county] =>
[county_id] =>
[isp] =>
[isp_id] =>
[ip] => 122.11.137.55
))
header("Content-type: text/html; charset=utf-8");
header("Cache-Control: no-cache, must-revalidate");//我新加入的 不知道有用没
header("Pragma: no-cache");//我新加入的 不知道有用没require($_SERVER["DOCUMENT_ROOT"]."/include/api_title.php");$db->select_db("test");if($_GET['p']){
$start='1'+$_GET['p']*9;
$end='9'*$_GET['p']+9;
}else{
$start='1';
$end='9';
}if($_GET['p']<'381066'){
run($start,$end);
$nextp=$_GET['p']+1;
echo "当前页数为:".$nextp;
$jumpurl="getip.php?p=".$nextp;
echo "<script language=\"javascript\" type=\"text/javascript\">window.location.href=\"".$jumpurl."\";</script>
";
}function run($start,$end){
global $db;
$filename = "./ipaddr.txt";//需要读取的文件
$finiship = fopen("./finiship.txt", "a"); $array=getFileLines($filename,$start,$end);
foreach($array as $key=>$value){
usleep(120000);//120毫秒
$json2array[$key]=get_data($value); $SaveData[$key]=$json2array[$key]['data'];
//插入数据库
$sql=“这个省略了”;
$query = $db->query($sql);
fwrite($finiship, $value);//写入完成文件
}
fclose($finiship);
}function getFileLines($filename, $startLine = 1, $endLine = 50, $method = 'rb'){
$content = array(); if (version_compare(PHP_VERSION, '5.1.0', '>=')) { // 判断php版本(因为要用到SplFileObject,PHP>=5.1.0)
$count = $endLine - $startLine;
$fp = new SplFileObject($filename, $method);
$fp->seek($startLine - 1); // 转到第N行, seek方法参数从0开始计数
for ($i = 0; $i <= $count; ++$i) {
$content[] = $fp->current(); // current()获取当前行内容
$fp->next(); // 下一行
}
} else { //PHP<5.1
$fp = fopen($filename, $method);
if (!$fp)
return 'error:can not read file';
for ($i = 1; $i < $startLine; ++$i) { // 跳过前$startLine行
fgets($fp);
} for ($i; $i <= $endLine; ++$i) {
$content[] = fgets($fp); // 读取文件行内容
}
fclose($fp);
}
return array_filter($content); // array_filter过滤:false,null,''
} function get_data($value){
$url = "http://ip.taobao.com/service/getIpInfo.php?ip=".$value;
$ch = curl_init();
$timeout = 1;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
//在需要用户检测的网页里需要增加下面两行
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
//curl_setopt($ch, CURLOPT_USERPWD, US_NAME.":".US_PWD);
$contents = curl_exec($ch);
curl_close($ch);
return $json2array=json_decode($contents,true);
}
header("Cache-Control: no-cache, must-revalidate");//我新加入的 不知道有用没
header("Pragma: no-cache");//我新加入的 不知道有用没
起了作用
浏览器一天没死了
但是跟我的需求是不同的,我需要知道我已经存储的这380W个IP是个什么情况……所以 还是要通过淘宝的API来查找