这里我以mysql查询日志为源文件输入,直接显示到网页中查看。
<?php $file = 'mysqld-slow.log'; $fp = fopen($file, "r"); $line = 5000; $pos = -2; $t = " "; $data = " "; while ($line > 0) { while ($t != "\n") { $flag = fseek($fp, $pos, SEEK_END); if (fseek($fp, $pos, SEEK_END) == -1) { rewind($fp); $t = "\n"; $line = 0; } else { $t = fgetc($fp); $pos--; } } $t = " "; $line--; } while(!feof($fp)){ $data .= fgets($fp); $data .= '<br />'; } fclose($fp); echo $data ?>
<?php $file = '/path/to/file'; $fp = fopen($file, "r"); $line = 2000; $pos = -2; $t = " "; $data = " "; while ($line > 0) { while ($t != "\n") { $flag = fseek($fp, $pos, SEEK_END); if (fseek($fp, $pos, SEEK_END) == -1) { rewind($fp); $t = "\n"; $line = 0; } else { $t = fgetc($fp); $pos--; } } $t = " "; $line--; } while(!feof($fp)){ $data .= fgets($fp); $data .= '<br />'; } fclose($fp); echo $data ?>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。