php超大ファイルfseekを読み込む

4226 ワード

function readMaxFile($fp , $start = 0)
{
   $tag = "
"; $i = 0; $content = ''; while($i < 20) { if (feof($fp)) { return 0; } fseek($fp, $start, SEEK_SET); $res = fread($fp, 1); $content .= $res; if (substr($content, -strlen($tag)) == $tag) { $i++; echo $i." ->+++ +++"."
"; } $start+=1; if (feof($fp)) { return 0; } } sleep(3); echo " ".$start." "; return $start; } $fp = fopen("install.log", "r+"); $re = readMaxFile($fp, 0); for($i=0; $i<100; $i++) { if ($re==0) { echo 'a 0 '; break; } $re = readMaxFile($fp, $re); } fclose($fp); echo " ";