Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 548 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
443 liveuser 1
<?php
2
 
636 liveuser 3
/*
4
 
5
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2015~2024 Min-Jhin,Chen
7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
 
443 liveuser 25
#使用命名空間qbpwcf
26
namespace qbpwcf;
27
 
28
#匯入外部套件
29
require_once("qbpwcf/allInOne.php");
30
 
31
#設定要讀取的檔案
32
$file="./assets of stringProcess/https_error_504.log.txt";
33
 
34
#函式說明:
35
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
36
#回傳的變數說明:
37
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
38
#$result["error"],錯誤訊息提示.
39
#$result["warning"],警告訊息.
40
#$result["function"],當前執行的函數名稱.
41
#$result["fileContent"],爲檔案的內容陣列.
42
#$result["lineCount"],爲檔案內容總共的行數.
43
#$result["fullContent"],為檔案的完整內容.
44
#$result["base64data"],為檔案的base64內容.
45
#$result["mimeType"],為檔案的mime type.
46
#必填參數:
47
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
48
$conf["filePositionAndName"]=$file;
49
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
50
$conf["fileArgu"]=__FILE__;
51
#可省略參數:
52
#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
53
$conf["web"]="false";
54
#參考資料:
55
#file(),取得檔案內容的行數.
56
#file=>http:#php.net/manual/en/function.file.php
57
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
58
#filesize=>http://php.net/manual/en/function.filesize.php
59
#參考資料:
60
#無.
61
#備註:
62
#無.
63
$getFileContent=fileAccess::getFileContent($conf);
64
unset($conf);
65
 
66
#如果執行失敗
67
if($getFileContent["status"]==="false")
68
{
69
 
70
	#印出錯誤
71
	var_dump($getFileContent);
72
 
73
	#錯誤離開
74
	exit(1);
75
 
76
}#if end
77
 
78
#初始化結果
79
$result["content"]=array();
80
 
81
#針對每個行內容
82
foreach($getFileContent["fileContent"] as $lineNo => $lineContent)
83
{
84
 
85
	#將字串進行解析,取得兩個關鍵字中間的內容.
86
	#回傳結果:
87
	#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
88
	#$result["function"],當前執行的函式內容.
89
	#$result["error"],錯誤訊息陣列.
90
	#$result["content"],取得的內容.
91
	#$result["oriStr"],原始的內容.
92
	#$result["found"],是否有找到符合條件的內容.
93
	#必填參數:
94
	#$conf["input"],字串,要處理的字串.
95
	$conf["input"]=$lineContent;
96
	#$conf["startKeyWord"],字串,開頭的關鍵字.
97
	$conf["startKeyWord"]="[";
98
	#$conf["endKeyWord"],字串,結束的關鍵字.
99
	$conf["endKeyWord"]="]";
100
	#可省略參數:
101
	#無.
102
	#參考資料:
103
	#無.
104
	#備註:
105
	#無.
106
	$getContentBetweenKeyWord=stringProcess::getContentBetweenKeyWord($conf);
107
	unset($conf);
108
 
109
	#如果執行失敗
110
	if($getContentBetweenKeyWord["status"]==="false")
111
	{
112
 
113
		#印出錯誤
114
		var_dump($getContentBetweenKeyWord);
115
 
116
		#錯誤離開
117
		exit(1);
118
 
119
	}#if end
120
 
121
	#var_dump($getContentBetweenKeyWord);exit;
122
 
123
	#如果無符合的內容
124
	if($getContentBetweenKeyWord["found"]==="false")
125
	{
126
 
127
		#下一行
128
		continue;
129
 
130
	}#if end
131
 
132
	#取得日期與時間
133
	$dateTime=$getContentBetweenKeyWord["content"];
134
 
135
	#var_dump($getContentBetweenKeyWord);
136
 
137
	#依照日期與時間記錄 對應的內容
138
	$result["content"][$dateTime][]=$lineContent;
139
 
140
}#foreach end
141
 
142
#針對每個 時間點
143
foreach($result["content"] as $dateTime => $lines)
144
{
145
 
146
	#取得同時間的資料有多少筆
147
	$count=count($lines);
148
 
149
	#如果沒有同時間的資料
150
	if($count<2)
151
	{
152
 
153
		#下一輪
154
		continue;
155
 
156
	}#if end
157
 
158
	#印出時間
159
	echo "Date Time:".$dateTime." ".$count." requests in same time".PHP_EOL;
160
 
161
	#針對每行內容
162
	foreach($lines as $line)
163
	{
164
 
165
		#印出記錄
166
		echo $line.PHP_EOL;
167
 
168
	}#foreach end
169
 
170
	#結束這個時間的記錄
171
	echo PHP_EOL;
172
 
173
}#foreach end
174
 
175
?>