 |
|
1
Tianpu Dec 26, 2011
<?php // error_reporting(0); $time_start = getmicrotime(); session_start(); $key = $_GET['key']; $time = $_GET['time']; $files = array('csdn.sql'); $keyminlen = 4; $step = 16000; $limit = 1024000; $lend = "\n"; $path = './temp/'; $data = './data/'; if($_GET['action']=='clear'){ unlink($path.$_SESSION['sid']); $_SESSION['sid'] = ''; } $sid = $_SESSION['sid']; if($sid==''){ $sid = session_id(); $_SESSION['sid'] = $sid; } function getmicrotime(){ list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } function cache($file,$str){ global $sid,$path,$limit,$key,$time; $ssize = filesize($path.$sid); if($ssize>$limit){ echo "<a href=temp/$sid> result right click to save as</a><br>"; echo "<br><br><a href=?action=clear>get another keyword</a><br><br>processed in $time seconds"; die('too many result, contact us if you do need it'); } if(preg_match_all("/(.*?)".$key."(.*?)\\n/i",$str,$match)){ if($ssize>0) file_put_contents($path.$sid,$match[0],FILE_APPEND); else file_put_contents($path.$sid,$file."\n".$match[0],FILE_APPEND); } print_r(preg_last_error()); } function large($file,$start,$repeat,$plus){ global $step,$data,$key; $r = array(); $return = $temp = ''; $i = 0; $handle = fopen($data.$file,'r'); while($i<$repeat && !feof($handle)){ fseek($handle, $start, SEEK_SET); if($i==0) $temp = $plus.fread($handle,$step); else $temp = fread($handle,$step); if(strpos($temp,$key)){ $r[1].= $temp; $r[2] = true; $r[3] = substr($temp,-60); } $r[0]+= $step; $start+= $step; $i++; } fclose($handle); return $r; } function process($file,$start,$lnum){ global $step,$lend,$fid,$time,$time_start,$key,$data; $r = array(); $filesize = filesize($data.$file); $block = 51200000; $repeat = 10; $tstr = ''; $count = 0; while($count<$block && $start<$filesize){ $temp = large($file,$start,$repeat,$temp[3]); $start+=$temp[0]; $count+=$temp[0]; if($temp[2]) cache($file,$temp[1]); } $time+=getmicrotime()-$time_start; echo "<br><br>processed in $time seconds<br> continue<br ><br>"; if($start>=$filesize){ $fid++; die($file.' KO.<br>continue to another<br><meta http-equiv="Refresh" content="0;url=?key='.rawurlencode($key).'&time='.$time.'&fid='.$fid.'">'); } $r[] = $start; $r[] = $lnum; return $r; } $start = $_GET['start']; $lnum = $_GET['lnum']; $fid = $_GET['fid']; if($fid<1) $fid = 0; if($fid>count($files)-1){ if(filesize($path.$sid)>0){ echo "<a href=temp/$sid> result right click to save as</a><br>"; echo '<pre>'.file_get_contents($path.$sid).'</pre>'; } else echo 'no result'; echo "<br><br><a href=?action=clear>get another keyword</a><br><br>processed in $time seconds"; die(); } $file = $files[$fid]; if($key=='') die('<form>keyword: <input type=text name=key> <input type=submit></form>'); else{ if(strlen($key)<$keyminlen) die('keyword too short'); if($start<1) $start = 0; if($lnum<2) $lnum = 1; $t = process($file,$start,$lnum); $time+=getmicrotime()-$time_start; echo '<meta http-equiv="Refresh" content="0;url=?key='.rawurlencode($key).'&fid='.$fid.'&time='.$time.'&start='.$t[0].'&lnum='.$t[1].'&file='.$file.'">'; } ?>
|