Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 443 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
443 liveuser 1
<?php
2
 
3
#使用命名空間qbpwcf
4
namespace qbpwcf;
5
 
6
#匯入外部套件
7
require_once("qbpwcf/allInOne.php");
8
 
9
#設定要讀取的檔案
10
$file="./assets of stringProcess/https_error_504.log.txt";
11
 
12
#函式說明:
13
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
14
#回傳的變數說明:
15
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
16
#$result["error"],錯誤訊息提示.
17
#$result["warning"],警告訊息.
18
#$result["function"],當前執行的函數名稱.
19
#$result["fileContent"],爲檔案的內容陣列.
20
#$result["lineCount"],爲檔案內容總共的行數.
21
#$result["fullContent"],為檔案的完整內容.
22
#$result["base64data"],為檔案的base64內容.
23
#$result["mimeType"],為檔案的mime type.
24
#必填參數:
25
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
26
$conf["filePositionAndName"]=$file;
27
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
28
$conf["fileArgu"]=__FILE__;
29
#可省略參數:
30
#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
31
$conf["web"]="false";
32
#參考資料:
33
#file(),取得檔案內容的行數.
34
#file=>http:#php.net/manual/en/function.file.php
35
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
36
#filesize=>http://php.net/manual/en/function.filesize.php
37
#參考資料:
38
#無.
39
#備註:
40
#無.
41
$getFileContent=fileAccess::getFileContent($conf);
42
unset($conf);
43
 
44
#如果執行失敗
45
if($getFileContent["status"]==="false")
46
{
47
 
48
	#印出錯誤
49
	var_dump($getFileContent);
50
 
51
	#錯誤離開
52
	exit(1);
53
 
54
}#if end
55
 
56
#初始化結果
57
$result["content"]=array();
58
 
59
#針對每個行內容
60
foreach($getFileContent["fileContent"] as $lineNo => $lineContent)
61
{
62
 
63
	#將字串進行解析,取得兩個關鍵字中間的內容.
64
	#回傳結果:
65
	#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
66
	#$result["function"],當前執行的函式內容.
67
	#$result["error"],錯誤訊息陣列.
68
	#$result["content"],取得的內容.
69
	#$result["oriStr"],原始的內容.
70
	#$result["found"],是否有找到符合條件的內容.
71
	#必填參數:
72
	#$conf["input"],字串,要處理的字串.
73
	$conf["input"]=$lineContent;
74
	#$conf["startKeyWord"],字串,開頭的關鍵字.
75
	$conf["startKeyWord"]="[";
76
	#$conf["endKeyWord"],字串,結束的關鍵字.
77
	$conf["endKeyWord"]="]";
78
	#可省略參數:
79
	#無.
80
	#參考資料:
81
	#無.
82
	#備註:
83
	#無.
84
	$getContentBetweenKeyWord=stringProcess::getContentBetweenKeyWord($conf);
85
	unset($conf);
86
 
87
	#如果執行失敗
88
	if($getContentBetweenKeyWord["status"]==="false")
89
	{
90
 
91
		#印出錯誤
92
		var_dump($getContentBetweenKeyWord);
93
 
94
		#錯誤離開
95
		exit(1);
96
 
97
	}#if end
98
 
99
	#var_dump($getContentBetweenKeyWord);exit;
100
 
101
	#如果無符合的內容
102
	if($getContentBetweenKeyWord["found"]==="false")
103
	{
104
 
105
		#下一行
106
		continue;
107
 
108
	}#if end
109
 
110
	#取得日期與時間
111
	$dateTime=$getContentBetweenKeyWord["content"];
112
 
113
	#var_dump($getContentBetweenKeyWord);
114
 
115
	#依照日期與時間記錄 對應的內容
116
	$result["content"][$dateTime][]=$lineContent;
117
 
118
}#foreach end
119
 
120
#針對每個 時間點
121
foreach($result["content"] as $dateTime => $lines)
122
{
123
 
124
	#取得同時間的資料有多少筆
125
	$count=count($lines);
126
 
127
	#如果沒有同時間的資料
128
	if($count<2)
129
	{
130
 
131
		#下一輪
132
		continue;
133
 
134
	}#if end
135
 
136
	#印出時間
137
	echo "Date Time:".$dateTime." ".$count." requests in same time".PHP_EOL;
138
 
139
	#針對每行內容
140
	foreach($lines as $line)
141
	{
142
 
143
		#印出記錄
144
		echo $line.PHP_EOL;
145
 
146
	}#foreach end
147
 
148
	#結束這個時間的記錄
149
	echo PHP_EOL;
150
 
151
}#foreach end
152
 
153
?>