php操作大文件数据的方法
1 @ini_set('memory_limit', '1G'); 2 $fp = fopen('E:/code/share/log.txt', 'r'); 3 if(fseek ($fp, 0, SEEK_END)!==-1){ 4 $maxPos = ftell($fp); 5 $last = 0; 6 for($i=1; $i<$maxPos; $i++){ 7 fseek ($fp, $maxPos - $i, SEEK_SET); 8 $data = fgets($fp); 9 $cur = strlen(trim($data)); 10 if($last > 0 && $last > $cur){ 11 echo $lastdata."----".$i."\n"; 12 } 13 else{ 14 $lastdata = $data; 15 } 16 $last = $cur; 17 if($i>50000) exit; 18 } 19 } 20 21 fclose($fp); 22 exit("\n");