$file='./new.txt'; $fp = fopen($file, "r");
$chunk = 4096;//一次处理1M的字节 1M=1024*1024
$fs = filesize($file);
//$max = ($fs == PHP_INT_MAX) ? PHP_INT_MAX : filesize($file);
$readData ='';
for ($len = 0; $len < $max; $len += $chunk) {
$seekSize = ($max - $len > $chunk) ? $chunk : $max - $len;
fseek($fp, ($len + $seekSize) * -1, SEEK_END);
// $readData = fread($fp, $seekSize) . $readData;
// var_dump($readData);
// echo '<br>';
//排序$readData
$readData = fread($fp, $seekSize);
sorting_array($readData); //写入新文件
$t = fopen('./new.text', 'w');
fwrite($t,$readData);
fclose($t);
}
var_dump($readData); fclose($fp); //排序算法
function sorting_array($string){ } 目前只是把原始文件按块处理,里面可以经行排序,在吧新文件使用插入排序法,但是内存限制,各种超时,实现代码估计比较难