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
#初始化輸出
29
$output=array();
30
 
31
#取得 lib path
32
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../../../bin/libexec/folderOfUsrLib.php"),$output,$status);
33
 
34
#如果執行失敗
35
if($status!==0){
36
 
37
	#debug
38
	var_dump(__LINE__,$output);
39
 
40
	#結束執行,回傳shell 1.
41
	exit(1);
42
 
43
	}#if end
44
 
45
#儲存lib path
46
$folderOfUsrLib=$output[0];
47
 
48
#初始化輸出
49
$output=array();
50
 
51
#以該檔案的實際位置的 lib path 為 include path 首位
52
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../../../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);
53
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
54
 
55
#匯入套件
56
require_once("allInOne.php");
57
 
58
#建議的log位置
59
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";
60
 
61
#無窮迴圈
62
while(true){
63
 
64
	#函式說明:
65
	#一次取得純文字檔案的內容.
66
	#回傳結果:
67
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
68
	#$result["error"],錯誤訊息陣列.
69
	#$result["function"],當前執行的函數名稱.
70
	#$result["cmd"],執行的指令.
71
	#$result["content"],取得的檔案內容,若沒有內容則為null,反之為字串.
72
	#$result["length"],取得的內容長度.
73
	#$result["EOF"],識別是否已經到檔案結尾,"true"代表是,"false"代表不是.
74
	#$result["nextLine"],整數,下一行的行號,亦即下次來讀取下一行時,lineStart參數要給予的數值.
75
	#$result["fileSize"],整數,檔案的大小,用於下次來讀取下一行時,preFileSize參數要給予的數值.
76
	#必填參數:
77
	#$conf["file"],字串,檔案的路徑與名稱.
78
	$conf["file"]="ssl_access_log";
79
	#可省略參數:
80
 
81
	#如果有 $lineStart
82
	if(isset($lineStart)){
83
 
84
		#$conf["lineStart"],整數,要從第幾行開始,起始點為1.
85
		$conf["lineStart"]=$lineStart;
86
 
87
		}#if end
88
 
89
	#如果有 preFileSize 
90
	if(isset($preFileSize)){
91
 
92
		#$conf["preFileSize"],整數,上次透過本函式取得的fileSize結果,用於確認檔案是否有被rotate過,預設不設置.
93
		$conf["preFileSize"]=$preFileSize;
94
 
95
		}#if end
96
 
97
	#可省略參數:
98
	#無
99
	#參考資料:
100
	#無.
101
	#備註:
102
	#無
103
	$getTextFilePart=fileAccess::getTextFilePart($conf);
104
 
105
	#取得當前讀取的行號.
106
	$lineNo=$conf["lineStart"];
107
 
108
	#卸除變數,避免後續引用錯誤.
109
	unset($conf);
110
 
111
	#如果執行異常
112
	if($getTextFilePart["status"]==="false"){
113
 
114
		#debug
115
		var_dump($getTextFilePart);
116
 
117
		#結束執行並回傳 shell 1
118
		exit(1);
119
 
120
		}#if end
121
 
122
	#取得下次要取得的行號
123
	$lineStart=$getTextFilePart["nextLine"];
124
 
125
	#取得檔案的大小
126
	$preFileSize=(int)$getTextFilePart["fileSize"];
127
 
128
	#如果沒有內容
129
	if(!isset($getTextFilePart["content"])){
130
 
131
		#跳出 while loop
132
		break;
133
 
134
		}#if end
135
 
136
	#取得行內容
137
	$lineContent=$getTextFilePart["content"];
138
 
139
	#取得目前的記憶體使用狀況
140
	$memoeryUsage=\memory_get_usage();
141
 
142
	#提示取得的內容與記憶體使用狀況
143
	echo "memUsage:".$memoeryUsage." lineNo:".$lineNo." "."content:".$lineContent;
144
 
145
	#如果已經到檔案結尾了
146
	if($getTextFilePart["EOF"]==="true"){
147
 
148
		#跳出 while loop
149
		break;
150
 
151
		}#if end
152
 
153
	}#while end
154
 
155
?>