PHP 가 큰 파일 을 읽 고 보 여 주 는 간단 한 인 스 턴 스(추천)
PHP 코드:
<?php
class Test{
//
const LOG_PATH="E:\phpServer\Apache\logs\error.log";
const NGINX_LOG_PATH="E:\phpServer\
ginx\logs\error.log";
//
const PAGES=50;
public static function main(){
header("content-type:text/html;charset=utf-8");
if(!empty($_GET['action'])){
self::$_GET['action']();
exit;
}
}
public static function showApacheLogs(){
$test=new Test();
$result=$test->readLogs(self::LOG_PATH,self::PAGES);
$html="";
foreach($result as $line){
if(strpos($line,"error:")){
$line="<font color='red'>".$line."</font>";
}
$html.="<div class='line'>".$line."<div>";
}
echo $html;
}
public static function showNginxLogs(){
$test=new Test();
$result=$test->readLogs(self::NGINX_LOG_PATH,self::PAGES);
$html="";
foreach($result as $line){
if(strpos($line,"error")){
$line="<font color='red'>".$line."</font>";
}
$html.="<div class='line'>".$line."<div>";
}
echo $html;
}
/**
*
*/
private function readLogs($filePath,$num=20){
$fp = fopen($filePath,"r");
$pos = -2;
$eof = "";
$head = false; // Num ,
$lines = array();
while($num>0){
while($eof != "
"){
if(fseek($fp, $pos, SEEK_END)==0){ //fseek 0, -1
$eof = fgetc($fp);
$pos--;
}else{ // , , $pos
fseek($fp,0,SEEK_SET);
$head = true; // ,
break;
}
}
array_unshift($lines,fgets($fp));
if($head){ break; } // , , ,
$eof = "";
$num--;
}
fclose($fp);
return array_reverse($lines);
}
}
Test::main();
?>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
.logsBox{
margin:5px;
padding: 5px;
width: 600px;
background: #000;
color:#fff;
font-size: 13px;
float: left;
}
.logsBox .line{
margin: 12px 0;
}
</style>
<div class="logsBox apache">
<div class="line"> ...</div>
</div>
<div class="logsBox nginx">
<div class="line"> ...</div>
</div>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
function showLogs(api,showClass){
function readLogs(){
$.ajax({
url:api,
type:"get",
dataType:"text",
success:function(data){
$(showClass).html(data);
}
});
}
readLogs();
setInterval(readLogs,5000);
}
showLogs("?action=showNginxLogs",".nginx");
showLogs("?action=showApacheLogs",".apache");
});
</script>
이상 의 PHP 에서 큰 파일 을 읽 고 보 여 주 는 간단 한 인 스 턴 스(추천)는 바로 작은 편집 이 여러분 에 게 공유 하 는 모든 내용 입 니 다.참고 가 되 고 저 희 를 많이 사랑 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Laravel - 변환된 유효성 검사 규칙으로 API 요청 제공동적 콘텐츠를 위해 API를 통해 Laravel CMS에 연결하는 모바일 앱(또는 웹사이트) 구축을 고려하십시오. 이제 앱은 CMS에서 번역된 콘텐츠를 받을 것으로 예상되는 다국어 앱이 될 수 있습니다. 일반적으로 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.