Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
391 liveuser 1
<?php
2
 
3
/*
4
 
5
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2014~2026 MIN ZHI, 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
 
25
#使用命名空間qbpwcf
26
namespace qbpwcf;
27
 
28
#assets dir
29
$assetsDir="assets of fileAccess::getTextFilePart_20260708";
30
 
31
#初始化參數 lineStart
32
$lineStart=null;
33
 
34
#初始化參數 preFileSize
35
$preFileSize=null;
36
 
37
#無窮迴圈
38
while(true){
39
 
40
	#函式說明:
41
	#一次取得純文字檔案的內容.
42
	#回傳結果:
43
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
44
	#$result["error"],錯誤訊息陣列.
45
	#$result["function"],當前執行的函數名稱.
46
	#$result["cmd"],執行的指令.
47
	#$result["content"],取得的檔案內容.
48
	#$result["length"],取得的內容長度.
49
	#$result["EOF"],識別是否已經到檔案結尾,"true"代表是,"false"代表不是.
50
	#$result["nextLine"],整數,下一行的行號,亦即下次來讀取下一行時,lineStart參數要給予的數值.
51
	#$result["fileSize"],整數,檔案的大小,用於下次來讀取下一行時,preFileSize參數要給予的數值.
52
	#必填參數:
53
	#$conf["file"],字串,檔案的路徑與名稱.
54
	$conf["file"]=$assetsDir."/ssl_access_log";
55
	#可省略參數:
56
 
57
	#如果有 $lineStart
58
	if($lineStart!==null){
59
 
60
		#$conf["lineStart"],整數,要從第幾行開始,起始點為1.
61
		$conf["lineStart"]=$lineStart;
62
 
63
		}#if end
64
 
65
	#如果有 preFileSize 
66
	if($preFileSize!==null){
67
 
68
		#$conf["preFileSize"],整數,上次透過本函式取得的fileSize結果,用於確認檔案是否有被rotate過,預設不設置.
69
		$conf["preFileSize"]=$preFileSize;
70
 
71
		}#if end
72
 
73
	#可省略參數:
74
	#無
75
	#參考資料:
76
	#無.
77
	#備註:
78
	#無
79
	$getTextFilePart=fileAccess::getTextFilePart($conf);
80
 
81
	#取得當前讀取的行號.
82
	$lineNo=$conf["lineStart"];
83
 
84
	#卸除變數,避免後續引用錯誤.
85
	unset($conf);
86
 
87
	#如果執行異常
88
	if($getTextFilePart["status"]==="false"){
89
 
90
		#debug
91
		var_dump($getTextFilePart);
92
 
93
		#結束執行並回傳 shell 1
94
		exit(1);
95
 
96
		}#if end
97
 
98
	#取得下次要取得的行號
99
	$lineStart=$getTextFilePart["nextLine"];
100
 
101
	#取得檔案的大小
102
	$preFileSize=(int)$getTextFilePart["fileSize"];
103
 
104
	#取得行內容
105
	$lineContent=$getTextFilePart["content"];
106
 
107
	#取得目前的記憶體使用狀況
108
	$memoeryUsage=\memory_get_usage();
109
 
110
	#提示取得的內容與記憶體使用狀況
111
	echo "memUsage:".$memoeryUsage." lineNo:".$lineNo." "."content:".$lineContent.PHP_EOL;
112
 
113
	#如果已經到檔案結尾了
114
	if($getTextFilePart["EOF"]==="true"){
115
 
116
		#跳出 while loop
117
		break;
118
 
119
		}#if end
120
 
121
	}#while end