Subversion Repositories php-qbpwcf

Rev

Rev 3 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 226
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2015~2025 Min-Jhin,Chen
6
    Copyright (C) 2014~2025 MIN ZHI, CHEN
7
 
7
 
8
    This file is part of QBPWCF.
8
    This file is part of QBPWCF.
9
 
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
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
11
    it under the terms of the GNU General Public License as published by
Line 43... Line 43...
43
	#$arguments,陣列,為呼叫方法時所用的參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
44
	#參考資料:
44
	#參考資料:
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
46
	*/
46
	*/
47
	public function __call($method,$arguments){
47
	public function __call($method,$arguments){
48
		
48
 
49
		#取得當前執行的函式
49
		#取得當前執行的函式
50
		$result["function"]=__FUNCTION__;
50
		$result["function"]=__FUNCTION__;
51
		
51
 
52
		#設置執行不正常
52
		#設置執行不正常
53
		$result["status"]="false";
53
		$result["status"]="false";
54
		
54
 
55
		#設置執行錯誤
55
		#設置執行錯誤
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
57
		
57
 
58
		#設置所丟入的參數
58
		#設置所丟入的參數
59
		$result["error"][]=$arguments;
59
		$result["error"][]=$arguments;
60
		
60
 
61
		#回傳結果
61
		#回傳結果
62
		return $result;
62
		return $result;
63
		
63
 
64
		}#function __call end
64
		}#function __call end
65
		
65
 
66
	/*
66
	/*
67
	#函式說明:
67
	#函式說明:
68
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
68
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
69
	#回傳結果:
69
	#回傳結果:
70
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
70
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 75... Line 75...
75
	#$arguments,陣列,為呼叫方法時所用的參數.
75
	#$arguments,陣列,為呼叫方法時所用的參數.
76
	#參考資料:
76
	#參考資料:
77
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
77
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
78
	*/
78
	*/
79
	public static function __callStatic($method,$arguments){
79
	public static function __callStatic($method,$arguments){
80
		
80
 
81
		#取得當前執行的函式
81
		#取得當前執行的函式
82
		$result["function"]=__FUNCTION__;
82
		$result["function"]=__FUNCTION__;
83
		
83
 
84
		#設置執行不正常
84
		#設置執行不正常
85
		$result["status"]="false";
85
		$result["status"]="false";
86
		
86
 
87
		#設置執行錯誤
87
		#設置執行錯誤
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
89
		
89
 
90
		#設置所丟入的參數
90
		#設置所丟入的參數
91
		$result["error"][]=$arguments;
91
		$result["error"][]=$arguments;
92
		
92
 
93
		#回傳結果
93
		#回傳結果
94
		return $result;
94
		return $result;
95
		
95
 
96
		}#function __callStatic end
96
		}#function __callStatic end
97
 
97
 
98
	/*
98
	/*
99
	#函式說明:
99
	#函式說明:
100
	#延長php的執行時間,每呼叫一次會初始化執行時間爲0,然後設定下次可以執行多久.
100
	#延長php的執行時間,每呼叫一次會初始化執行時間爲0,然後設定下次可以執行多久.
Line 111... Line 111...
111
	#無.
111
	#無.
112
	#參考資料:
112
	#參考資料:
113
	#http://php.net/manual/en/function.set-time-limit.php
113
	#http://php.net/manual/en/function.set-time-limit.php
114
	*/
114
	*/
115
	public static function delayRunTimeExectionMax(&$conf){
115
	public static function delayRunTimeExectionMax(&$conf){
116
		
116
 
117
		#初始化要回傳的內容
117
		#初始化要回傳的內容
118
		$result=array();
118
		$result=array();
119
		
119
 
120
		#記錄當前執行的函數名稱
120
		#記錄當前執行的函數名稱
121
		$result["function"]=__FUNCTION__;
121
		$result["function"]=__FUNCTION__;
122
 
122
 
123
		#如果 $conf 不為陣列
123
		#如果 $conf 不為陣列
124
		if(gettype($conf)!="array"){
124
		if(gettype($conf)!="array"){
125
			
125
 
126
			#設置執行失敗
126
			#設置執行失敗
127
			$result["status"]="false";
127
			$result["status"]="false";
128
			
128
 
129
			#設置執行錯誤訊息
129
			#設置執行錯誤訊息
130
			$result["error"][]="\$conf變數須為陣列形態";
130
			$result["error"][]="\$conf變數須為陣列形態";
131
 
131
 
132
			#如果傳入的參數為 null
132
			#如果傳入的參數為 null
133
			if($conf==null){
133
			if($conf==null){
134
				
134
 
135
				#設置執行錯誤訊息
135
				#設置執行錯誤訊息
136
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
136
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
137
				
137
 
138
				}#if end
138
				}#if end
139
 
139
 
140
			#回傳結果
140
			#回傳結果
141
			return $result;
141
			return $result;
142
			
142
 
143
			}#if end
143
			}#if end
144
 
144
 
145
		#檢查參數
145
		#檢查參數
146
		#函式說明:
146
		#函式說明:
147
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
147
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
Line 158... Line 158...
158
		#必填寫的參數:
158
		#必填寫的參數:
159
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
159
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
160
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
160
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
161
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
161
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
162
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("sec");
162
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("sec");
163
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
163
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
164
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("integer");
164
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("integer");
165
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
165
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
166
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
166
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
167
		#可以省略的參數:
167
		#可以省略的參數:
168
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
168
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
169
		$conf["variableCheck::checkArguments"]["variableCheck::checkArguments"]["canBeEmptyString"]="false";
169
		$conf["variableCheck::checkArguments"]["variableCheck::checkArguments"]["canBeEmptyString"]="false";
170
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
170
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
171
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("asc");
171
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("asc");
172
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
172
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
173
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
173
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
174
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
174
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
175
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
175
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
176
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
176
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
177
		#$conf["arrayCountEqualCheck"][]=array();
177
		#$conf["arrayCountEqualCheck"][]=array();
Line 180... Line 180...
180
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
180
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
181
		unset($conf["variableCheck::checkArguments"]);
181
		unset($conf["variableCheck::checkArguments"]);
182
 
182
 
183
		#如果檢查參數失敗
183
		#如果檢查參數失敗
184
		if($checkArguments["status"]=="false"){
184
		if($checkArguments["status"]=="false"){
185
			
185
 
186
			#設置執行失敗
186
			#設置執行失敗
187
			$result["status"]="false";
187
			$result["status"]="false";
188
			
188
 
189
			#設置執行錯誤訊息
189
			#設置執行錯誤訊息
190
			$result["error"]=$checkArguments;
190
			$result["error"]=$checkArguments;
191
 
191
 
192
			#回傳結果
192
			#回傳結果
193
			return $result;
193
			return $result;
194
			
194
 
195
			}#if end
195
			}#if end
196
			
196
 
197
		#如果檢查不通過
197
		#如果檢查不通過
198
		if($checkArguments["passed"]=="false"){
198
		if($checkArguments["passed"]=="false"){
199
			
199
 
200
			#設置執行失敗
200
			#設置執行失敗
201
			$result["status"]="false";
201
			$result["status"]="false";
202
			
202
 
203
			#設置執行錯誤訊息
203
			#設置執行錯誤訊息
204
			$result["error"]=$checkArguments;
204
			$result["error"]=$checkArguments;
205
 
205
 
206
			#回傳結果
206
			#回傳結果
207
			return $result;
207
			return $result;
208
			
208
 
209
			}#if end
209
			}#if end
210
			
210
 
211
		#初始化執行時間爲0,然後再延長$conf["sec"] 秒
211
		#初始化執行時間爲0,然後再延長$conf["sec"] 秒
212
		$setupResult=set_time_limit($conf["sec"]);
212
		$setupResult=set_time_limit($conf["sec"]);
213
		
213
 
214
		#如果爲 FALSE
214
		#如果爲 FALSE
215
		if($setupResult==FALSE){
215
		if($setupResult==FALSE){
216
			
216
 
217
			#設置執行不正常
217
			#設置執行不正常
218
			$result["status"]="false";
218
			$result["status"]="false";
219
			
219
 
220
			#設置執行錯誤訊息
220
			#設置執行錯誤訊息
221
			$result["error"]="初始與重置執行時間上限失敗";
221
			$result["error"]="初始與重置執行時間上限失敗";
222
			
222
 
223
			#回傳結果
223
			#回傳結果
224
			return $result;
224
			return $result;
225
			
225
 
226
			}#if end
226
			}#if end
227
			
227
 
228
		#執行到這邊代表執行正常
228
		#執行到這邊代表執行正常
229
		$result["status"]="true";
229
		$result["status"]="true";
230
		
230
 
231
		#回傳結果
231
		#回傳結果
232
		return $result;
232
		return $result;
233
		
233
 
234
		}#function delayRunTimeExectionMax end
234
		}#function delayRunTimeExectionMax end
235
		
235
 
236
	/*
236
	/*
237
	#函式說明:
237
	#函式說明:
238
	#顯示目前的php設定值
238
	#顯示目前的php設定值
239
	#回傳的結果:
239
	#回傳的結果:
240
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
240
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
Line 253... Line 253...
253
	#http://www.php.net/manual/en/function.ini-get-all.php
253
	#http://www.php.net/manual/en/function.ini-get-all.php
254
	#備註:
254
	#備註:
255
	#無.
255
	#無.
256
	*/
256
	*/
257
	public static function showSettings(&$conf){
257
	public static function showSettings(&$conf){
258
		
258
 
259
		#初始化要回傳的內容
259
		#初始化要回傳的內容
260
		$result=array();
260
		$result=array();
261
		
261
 
262
		#記錄當前執行的函數名稱
262
		#記錄當前執行的函數名稱
263
		$result["function"]=__FUNCTION__;
263
		$result["function"]=__FUNCTION__;
264
 
264
 
265
		#如果 $conf 不為陣列
265
		#如果 $conf 不為陣列
266
		if(gettype($conf)!="array"){
266
		if(gettype($conf)!="array"){
267
			
267
 
268
			#設置執行失敗
268
			#設置執行失敗
269
			$result["status"]="false";
269
			$result["status"]="false";
270
			
270
 
271
			#設置執行錯誤訊息
271
			#設置執行錯誤訊息
272
			$result["error"][]="\$conf變數須為陣列形態";
272
			$result["error"][]="\$conf變數須為陣列形態";
273
 
273
 
274
			#如果傳入的參數為 null
274
			#如果傳入的參數為 null
275
			if($conf==null){
275
			if($conf==null){
276
				
276
 
277
				#設置執行錯誤訊息
277
				#設置執行錯誤訊息
278
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
278
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
279
				
279
 
280
				}#if end
280
				}#if end
281
 
281
 
282
			#回傳結果
282
			#回傳結果
283
			return $result;
283
			return $result;
284
			
284
 
285
			}#if end
285
			}#if end
286
 
286
 
287
		#檢查參數
287
		#檢查參數
288
		#函式說明:
288
		#函式說明:
289
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
289
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
Line 300... Line 300...
300
		#必填寫的參數:
300
		#必填寫的參數:
301
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
301
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
302
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
302
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
303
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
303
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
304
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("default");
304
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("default");
305
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
305
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
306
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
306
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
307
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
307
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
308
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
308
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
309
		#可以省略的參數:
309
		#可以省略的參數:
310
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
310
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
311
		$conf["variableCheck::checkArguments"]["variableCheck::checkArguments"]["canBeEmptyString"]="false";
311
		$conf["variableCheck::checkArguments"]["variableCheck::checkArguments"]["canBeEmptyString"]="false";
312
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
312
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
313
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("settingsName","showAll");
313
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("settingsName","showAll");
314
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
314
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
315
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string");
315
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string");
316
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
316
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
317
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array("display_errors","upload_max_filesize","post_max_size","output_buffering","session.auto_start","memory_limit"),"false");
317
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array("display_errors","upload_max_filesize","post_max_size","output_buffering","session.auto_start","memory_limit"),"false");
318
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
318
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
319
		#$conf["arrayCountEqualCheck"][]=array();
319
		#$conf["arrayCountEqualCheck"][]=array();
Line 322... Line 322...
322
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
322
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
323
		unset($conf["variableCheck::checkArguments"]);
323
		unset($conf["variableCheck::checkArguments"]);
324
 
324
 
325
		#如果檢查參數失敗
325
		#如果檢查參數失敗
326
		if($checkArguments["status"]=="false"){
326
		if($checkArguments["status"]=="false"){
327
			
327
 
328
			#設置執行失敗
328
			#設置執行失敗
329
			$result["status"]="false";
329
			$result["status"]="false";
330
			
330
 
331
			#設置執行錯誤訊息
331
			#設置執行錯誤訊息
332
			$result["error"]=$checkArguments;
332
			$result["error"]=$checkArguments;
333
 
333
 
334
			#回傳結果
334
			#回傳結果
335
			return $result;
335
			return $result;
336
			
336
 
337
			}#if end
337
			}#if end
338
			
338
 
339
		#如果檢查不通過
339
		#如果檢查不通過
340
		if($checkArguments["passed"]=="false"){
340
		if($checkArguments["passed"]=="false"){
341
			
341
 
342
			#設置執行失敗
342
			#設置執行失敗
343
			$result["status"]="false";
343
			$result["status"]="false";
344
			
344
 
345
			#設置執行錯誤訊息
345
			#設置執行錯誤訊息
346
			$result["error"]=$checkArguments;
346
			$result["error"]=$checkArguments;
347
 
347
 
348
			#回傳結果
348
			#回傳結果
349
			return $result;
349
			return $result;
350
			
350
 
351
			}#if end
351
			}#if end
352
		
352
 
353
		#如果要顯示所有設定
353
		#如果要顯示所有設定
354
		if($conf["showAll"]==="true"){
354
		if($conf["showAll"]==="true"){
355
			
355
 
356
			#取得設定值
356
			#取得設定值
357
			$config=ini_get_all();
357
			$config=ini_get_all();
358
			
358
 
359
			#如果取得設定值失敗
359
			#如果取得設定值失敗
360
			if($config==FALSE){
360
			if($config==FALSE){
361
				
361
 
362
				#設置執行不正常
362
				#設置執行不正常
363
				$result["status"]="true";
363
				$result["status"]="true";
364
						
364
 
365
				#設置錯誤訊息
365
				#設置錯誤訊息
366
				$result["error"][]="取得所有設定值失敗";		
366
				$result["error"][]="取得所有設定值失敗";
367
							
367
 
368
				#回傳結果
368
				#回傳結果
369
				return $result;
369
				return $result;
370
				
370
 
371
				}#if end
371
				}#if end
372
				
372
 
373
			#反之
373
			#反之
374
			else{
374
			else{
375
				
375
 
376
				#取得設定值
376
				#取得設定值
377
				$result["content"]=&$config;
377
				$result["content"]=&$config;
378
				
378
 
379
				}#else end									
379
				}#else end
380
			
380
 
381
			}#if end
381
			}#if end
382
		
382
 
383
		#反之
383
		#反之
384
		else{
384
		else{
385
			
385
 
386
			#針對每個要顯示的設定值
386
			#針對每個要顯示的設定值
387
			foreach($conf["settingsName"] as $key=>$value){
387
			foreach($conf["settingsName"] as $key=>$value){
388
				
388
 
389
				#檢查設定值
389
				#檢查設定值
390
				$config=ini_get($value);
390
				$config=ini_get($value);
391
				
391
 
392
				#如果取得設定值失敗
392
				#如果取得設定值失敗
393
				if($config==FALSE){
393
				if($config==FALSE){
394
					
394
 
395
					#設置執行不正常
395
					#設置執行不正常
396
					$result["status"]="true";
396
					$result["status"]="true";
397
							
397
 
398
					#設置錯誤訊息
398
					#設置錯誤訊息
399
					$result["error"][]="參數「".$value."」不存在";		
399
					$result["error"][]="參數「".$value."」不存在";
400
								
400
 
401
					#回傳結果
401
					#回傳結果
402
					return $result;
402
					return $result;
403
					
403
 
404
					}#if end
404
					}#if end
405
				
405
 
406
				#反之
406
				#反之
407
				else{
407
				else{
408
					
408
 
409
					#取得設定值
409
					#取得設定值
410
					$result["content"][$value]=$config;
410
					$result["content"][$value]=$config;
411
					
411
 
412
					}#else end
412
					}#else end
413
								
413
 
414
				}#foreach end
414
				}#foreach end
415
			
415
 
416
			}#else 
416
			}#else
417
		
417
 
418
		#設置執行正常
418
		#設置執行正常
419
		$result["status"]="true";
419
		$result["status"]="true";
420
		
420
 
421
		#回傳結果
421
		#回傳結果
422
		return $result;
422
		return $result;
423
					
423
 
424
		}#function showSettings end
424
		}#function showSettings end
425
	
425
 
426
	/*	
426
	/*
427
	#函式說明:
427
	#函式說明:
428
	#將php設定檔常用的設定進行調整使之變成適用於開發模式、釋出模式、或自訂要調整哪些設定值
428
	#將php設定檔常用的設定進行調整使之變成適用於開發模式、釋出模式、或自訂要調整哪些設定值
429
	#回傳結果:
429
	#回傳結果:
430
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
430
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
431
	#$result["error"],錯誤訊息陣列.
431
	#$result["error"],錯誤訊息陣列.
Line 442... Line 442...
442
	#各個參數適用的修改方式的解說=>http://hi.baidu.com/richardali/item/d28104083c70c638a2332a60
442
	#各個參數適用的修改方式的解說=>http://hi.baidu.com/richardali/item/d28104083c70c638a2332a60
443
	#備註:
443
	#備註:
444
	#使用該函式後,網頁會無法顯示。
444
	#使用該函式後,網頁會無法顯示。
445
	*/
445
	*/
446
	public static function changeSettings(&$conf){
446
	public static function changeSettings(&$conf){
447
		
447
 
448
		#初始化要回傳的結果
448
		#初始化要回傳的結果
449
		$result=array();
449
		$result=array();
450
 
450
 
451
		#儲存當前執行的函數
451
		#儲存當前執行的函數
452
		$result["function"]=__FUNCTION__;
452
		$result["function"]=__FUNCTION__;
453
 
453
 
454
		#如果 $conf 不為陣列
454
		#如果 $conf 不為陣列
455
		if(gettype($conf)!="array"){
455
		if(gettype($conf)!="array"){
456
			
456
 
457
			#設置執行失敗
457
			#設置執行失敗
458
			$result["status"]="false";
458
			$result["status"]="false";
459
			
459
 
460
			#設置執行錯誤訊息
460
			#設置執行錯誤訊息
461
			$result["error"][]="\$conf變數須為陣列形態";
461
			$result["error"][]="\$conf變數須為陣列形態";
462
 
462
 
463
			#如果傳入的參數為 null
463
			#如果傳入的參數為 null
464
			if($conf==null){
464
			if($conf==null){
465
				
465
 
466
				#設置執行錯誤訊息
466
				#設置執行錯誤訊息
467
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
467
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
468
				
468
 
469
				}#if end
469
				}#if end
470
 
470
 
471
			#回傳結果
471
			#回傳結果
472
			return $result;
472
			return $result;
473
	
473
 
474
			}#if end
474
			}#if end
475
	
475
 
476
		#檢查參數
476
		#檢查參數
477
		#函式說明:
477
		#函式說明:
478
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
478
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
479
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
479
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
480
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
480
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 489... Line 489...
489
		#必填寫的參數:
489
		#必填寫的參數:
490
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
490
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
491
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
491
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
492
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
492
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
493
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mode");
493
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mode");
494
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
494
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
495
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
495
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
496
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
496
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
497
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
497
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
498
		#可以省略的參數:
498
		#可以省略的參數:
499
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
499
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
500
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
500
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
501
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
501
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
502
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("customSettings");
502
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("customSettings");
503
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
503
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
504
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
504
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
505
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
505
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
506
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
506
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
507
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
507
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
508
		#$conf["arrayCountEqualCheck"][]=array();
508
		#$conf["arrayCountEqualCheck"][]=array();
509
		#參考資料來源:
509
		#參考資料來源:
510
		#array_keys=>http://php.net/manual/en/function.array-keys.php
510
		#array_keys=>http://php.net/manual/en/function.array-keys.php
511
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
511
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
512
		unset($conf["variableCheck::checkArguments"]);
512
		unset($conf["variableCheck::checkArguments"]);
513
	
513
 
514
		#如果檢查失敗
514
		#如果檢查失敗
515
		if($checkArguments["status"]=="false"){
515
		if($checkArguments["status"]=="false"){
516
			
516
 
517
			#設置錯誤識別
517
			#設置錯誤識別
518
			$result["status"]="false";
518
			$result["status"]="false";
519
			
519
 
520
			#設置錯誤訊息
520
			#設置錯誤訊息
521
			$result["error"]=$checkArguments;
521
			$result["error"]=$checkArguments;
522
			
522
 
523
			#回傳結果
523
			#回傳結果
524
			return $result;
524
			return $result;
525
			
525
 
526
			}#if end
526
			}#if end
527
	
527
 
528
		#如果檢查不通過
528
		#如果檢查不通過
529
		if($checkArguments["passed"]=="false"){
529
		if($checkArguments["passed"]=="false"){
530
			
530
 
531
			#設置錯誤識別
531
			#設置錯誤識別
532
			$result["status"]="false";
532
			$result["status"]="false";
533
			
533
 
534
			#設置錯誤訊息
534
			#設置錯誤訊息
535
			$result["error"]=$checkArguments;
535
			$result["error"]=$checkArguments;
536
			
536
 
537
			#回傳結果
537
			#回傳結果
538
			return $result;
538
			return $result;
539
			
539
 
540
			}#if end
540
			}#if end
541
			
541
 
542
		#依據模式來進行設定
542
		#依據模式來進行設定
543
		switch($conf["mode"]){
543
		switch($conf["mode"]){
544
			
544
 
545
			#如果是給大家正式使用的狀況
545
			#如果是給大家正式使用的狀況
546
			case "release":
546
			case "release":
547
			
547
 
548
				#設置設定值
548
				#設置設定值
549
				
549
 
550
				#關閉顯示錯誤訊息
550
				#關閉顯示錯誤訊息
551
				$conf["customSettings"][]="display_errors=Off";
551
				$conf["customSettings"][]="display_errors=Off";
552
				
552
 
553
				#初始化計數為0
553
				#初始化計數為0
554
				$count=0;
554
				$count=0;
555
			
555
 
556
				#針對每個 $conf["customSettings"]
556
				#針對每個 $conf["customSettings"]
557
				foreach($conf["customSettings"] as $configStr){
557
				foreach($conf["customSettings"] as $configStr){
558
					
558
 
559
					#用 "=" 分割設定字串
559
					#用 "=" 分割設定字串
560
					#函式說明:
560
					#函式說明:
561
					#將固定格式的字串分開,並回傳分開的結果。
561
					#將固定格式的字串分開,並回傳分開的結果。
562
					#回傳的參數:
562
					#回傳的參數:
563
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
563
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 571... Line 571...
571
					$conf["stringProcess::spiltString"]["spiltSymbol"]="=";#爲以哪個符號作爲分割
571
					$conf["stringProcess::spiltString"]["spiltSymbol"]="=";#爲以哪個符號作爲分割
572
					#備註:
572
					#備註:
573
					#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
573
					#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
574
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
574
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
575
					unset($conf["stringProcess::spiltString"]);
575
					unset($conf["stringProcess::spiltString"]);
576
					
576
 
577
					#如果分割設定值字串失敗
577
					#如果分割設定值字串失敗
578
					if($spiltString["status"]=="false"){
578
					if($spiltString["status"]=="false"){
579
						
579
 
580
						#設置錯誤識別
580
						#設置錯誤識別
581
						$result["status"]="false";
581
						$result["status"]="false";
582
						
582
 
583
						#設置錯誤訊息
583
						#設置錯誤訊息
584
						$result["error"]=$spiltString;
584
						$result["error"]=$spiltString;
585
						
585
 
586
						#回傳結果
586
						#回傳結果
587
						return $result;
587
						return $result;
588
						
588
 
589
						}#if end
589
						}#if end
590
						
590
 
591
					#如果只有一段內容
591
					#如果只有一段內容
592
					if($spiltString["dataCounts"]=="1"){
592
					if($spiltString["dataCounts"]=="1"){
593
						
593
 
594
						#設置錯誤識別
594
						#設置錯誤識別
595
						$result["status"]="false";
595
						$result["status"]="false";
596
						
596
 
597
						#設置錯誤訊息
597
						#設置錯誤訊息
598
						$result["error"][]="設定值字串「".$configStr."」必須要用「=」來間隔設定屬性與其數值";
598
						$result["error"][]="設定值字串「".$configStr."」必須要用「=」來間隔設定屬性與其數值";
599
						
599
 
600
						#回傳結果
600
						#回傳結果
601
						return $result;
601
						return $result;
602
						
602
 
603
						}#if end
603
						}#if end
604
						
604
 
605
					#設定暫時的設定值
605
					#設定暫時的設定值
606
					$oldConfigValue=ini_set($spiltString["dataArray"][0],$spiltString["dataArray"][1]);
606
					$oldConfigValue=ini_set($spiltString["dataArray"][0],$spiltString["dataArray"][1]);
607
					
607
 
608
					#如果設定失敗
608
					#如果設定失敗
609
					if($oldConfigValue===false){
609
					if($oldConfigValue===false){
610
						
610
 
611
						#設置錯誤識別
611
						#設置錯誤識別
612
						$result["status"]="false";
612
						$result["status"]="false";
613
						
613
 
614
						#設置錯誤訊息
614
						#設置錯誤訊息
615
						$result["error"][]="將屬性「".$spiltString["dataArray"][0]."」設定為「".$spiltString["dataArray"][1]."」失敗";
615
						$result["error"][]="將屬性「".$spiltString["dataArray"][0]."」設定為「".$spiltString["dataArray"][1]."」失敗";
616
						
616
 
617
						#回傳結果
617
						#回傳結果
618
						return $result;
618
						return $result;
619
						
619
 
620
						}#if end
620
						}#if end
621
						
621
 
622
					#反之儲存舊的永久設地數值
622
					#反之儲存舊的永久設地數值
623
					else{
623
					else{
624
						
624
 
625
						#取得舊的設定值
625
						#取得舊的設定值
626
						$result["config"][$count]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
626
						$result["config"][$count]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
627
						$result["config"][$spiltString["dataArray"][0]]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
627
						$result["config"][$spiltString["dataArray"][0]]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
628
												
628
 
629
						#取得新的設定值
629
						#取得新的設定值
630
						$result["config"][$count]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
630
						$result["config"][$count]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
631
						$result["config"][$spiltString["dataArray"][0]]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
631
						$result["config"][$spiltString["dataArray"][0]]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
632
						
632
 
633
						#計數加1
633
						#計數加1
634
						$count++;
634
						$count++;
635
						
635
 
636
						}#else end
636
						}#else end
637
					
637
 
638
					}#foreach end
638
					}#foreach end
639
						
639
 
640
				#跳出switch
640
				#跳出switch
641
				break;
641
				break;
642
				
642
 
643
			#如果是開發狀態下
643
			#如果是開發狀態下
644
			case "develop";
644
			case "develop";
645
			
645
 
646
				#設置設定值
646
				#設置設定值
647
				
647
 
648
				#開啟顯示錯誤訊息
648
				#開啟顯示錯誤訊息
649
				$conf["customSettings"][]="display_errors=On";
649
				$conf["customSettings"][]="display_errors=On";
650
				
650
 
651
				#關閉使用記憶體的上限
651
				#關閉使用記憶體的上限
652
				$conf["customSettings"][]="memory_limit=-1";
652
				$conf["customSettings"][]="memory_limit=-1";
653
				
653
 
654
				#關閉php script執行的時間上限
654
				#關閉php script執行的時間上限
655
				$conf["customSettings"][]="max_execution_time=0";
655
				$conf["customSettings"][]="max_execution_time=0";
656
				
656
 
657
				#初始化計數為0
657
				#初始化計數為0
658
				$count=0;
658
				$count=0;
659
			
659
 
660
				#針對每個 $conf["customSettings"]
660
				#針對每個 $conf["customSettings"]
661
				foreach($conf["customSettings"] as $configStr){
661
				foreach($conf["customSettings"] as $configStr){
662
					
662
 
663
					#用 "=" 分割設定字串
663
					#用 "=" 分割設定字串
664
					#函式說明:
664
					#函式說明:
665
					#將固定格式的字串分開,並回傳分開的結果。
665
					#將固定格式的字串分開,並回傳分開的結果。
666
					#回傳的參數:
666
					#回傳的參數:
667
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
667
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 675... Line 675...
675
					$conf["stringProcess::spiltString"]["spiltSymbol"]="=";#爲以哪個符號作爲分割
675
					$conf["stringProcess::spiltString"]["spiltSymbol"]="=";#爲以哪個符號作爲分割
676
					#備註:
676
					#備註:
677
					#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
677
					#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
678
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
678
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
679
					unset($conf["stringProcess::spiltString"]);
679
					unset($conf["stringProcess::spiltString"]);
680
					
680
 
681
					#如果分割設定值字串失敗
681
					#如果分割設定值字串失敗
682
					if($spiltString["status"]=="false"){
682
					if($spiltString["status"]=="false"){
683
						
683
 
684
						#設置錯誤識別
684
						#設置錯誤識別
685
						$result["status"]="false";
685
						$result["status"]="false";
686
						
686
 
687
						#設置錯誤訊息
687
						#設置錯誤訊息
688
						$result["error"]=$spiltString;
688
						$result["error"]=$spiltString;
689
						
689
 
690
						#回傳結果
690
						#回傳結果
691
						return $result;
691
						return $result;
692
						
692
 
693
						}#if end
693
						}#if end
694
						
694
 
695
					#如果只有一段內容
695
					#如果只有一段內容
696
					if($spiltString["dataCounts"]=="1"){
696
					if($spiltString["dataCounts"]=="1"){
697
						
697
 
698
						#設置錯誤識別
698
						#設置錯誤識別
699
						$result["status"]="false";
699
						$result["status"]="false";
700
						
700
 
701
						#設置錯誤訊息
701
						#設置錯誤訊息
702
						$result["error"][]="設定值字串「".$configStr."」必須要用「=」來間隔設定屬性與其數值";
702
						$result["error"][]="設定值字串「".$configStr."」必須要用「=」來間隔設定屬性與其數值";
703
						
703
 
704
						#回傳結果
704
						#回傳結果
705
						return $result;
705
						return $result;
706
						
706
 
707
						}#if end
707
						}#if end
708
						
708
 
709
					#設定暫時的設定值
709
					#設定暫時的設定值
710
					$oldConfigValue=ini_set($spiltString["dataArray"][0],$spiltString["dataArray"][1]);
710
					$oldConfigValue=ini_set($spiltString["dataArray"][0],$spiltString["dataArray"][1]);
711
					
711
 
712
					#如果設定失敗
712
					#如果設定失敗
713
					if($oldConfigValue===false){
713
					if($oldConfigValue===false){
714
						
714
 
715
						#設置錯誤識別
715
						#設置錯誤識別
716
						$result["status"]="false";
716
						$result["status"]="false";
717
						
717
 
718
						#設置錯誤訊息
718
						#設置錯誤訊息
719
						$result["error"][]="將屬性「".$spiltString["dataArray"][0]."」設定為「".$spiltString["dataArray"][1]."」失敗";
719
						$result["error"][]="將屬性「".$spiltString["dataArray"][0]."」設定為「".$spiltString["dataArray"][1]."」失敗";
720
						
720
 
721
						#回傳結果
721
						#回傳結果
722
						return $result;
722
						return $result;
723
						
723
 
724
						}#if end
724
						}#if end
725
						
725
 
726
					#反之儲存舊的永久設地數值
726
					#反之儲存舊的永久設地數值
727
					else{
727
					else{
728
						
728
 
729
						#取得舊的設定值
729
						#取得舊的設定值
730
						$result["config"][$count]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
730
						$result["config"][$count]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
731
						$result["config"][$spiltString["dataArray"][0]]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
731
						$result["config"][$spiltString["dataArray"][0]]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
732
												
732
 
733
						#取得新的設定值
733
						#取得新的設定值
734
						$result["config"][$count]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
734
						$result["config"][$count]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
735
						$result["config"][$spiltString["dataArray"][0]]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
735
						$result["config"][$spiltString["dataArray"][0]]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
736
						
736
 
737
						#計數加1
737
						#計數加1
738
						$count++;
738
						$count++;
739
						
739
 
740
						}#else end
740
						}#else end
741
					
741
 
742
					}#foreach end		
742
					}#foreach end
743
								
743
 
744
				#跳出switch
744
				#跳出switch
745
				break;
745
				break;
746
				
746
 
747
			#如果是自訂設定值的狀態
747
			#如果是自訂設定值的狀態
748
			case "custom":
748
			case "custom":
749
					
749
 
750
				#初始化計數為0
750
				#初始化計數為0
751
				$count=0;
751
				$count=0;
752
			
752
 
753
				#針對每個 $conf["customSettings"]
753
				#針對每個 $conf["customSettings"]
754
				foreach($conf["customSettings"] as $configStr){
754
				foreach($conf["customSettings"] as $configStr){
755
					
755
 
756
					#用 "=" 分割設定字串
756
					#用 "=" 分割設定字串
757
					#函式說明:
757
					#函式說明:
758
					#將固定格式的字串分開,並回傳分開的結果。
758
					#將固定格式的字串分開,並回傳分開的結果。
759
					#回傳的參數:
759
					#回傳的參數:
760
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
760
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 768... Line 768...
768
					$conf["stringProcess::spiltString"]["spiltSymbol"]="=";#爲以哪個符號作爲分割
768
					$conf["stringProcess::spiltString"]["spiltSymbol"]="=";#爲以哪個符號作爲分割
769
					#備註:
769
					#備註:
770
					#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
770
					#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
771
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
771
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
772
					unset($conf["stringProcess::spiltString"]);
772
					unset($conf["stringProcess::spiltString"]);
773
					
773
 
774
					#如果分割設定值字串失敗
774
					#如果分割設定值字串失敗
775
					if($spiltString["status"]=="false"){
775
					if($spiltString["status"]=="false"){
776
						
776
 
777
						#設置錯誤識別
777
						#設置錯誤識別
778
						$result["status"]="false";
778
						$result["status"]="false";
779
						
779
 
780
						#設置錯誤訊息
780
						#設置錯誤訊息
781
						$result["error"]=$spiltString;
781
						$result["error"]=$spiltString;
782
						
782
 
783
						#回傳結果
783
						#回傳結果
784
						return $result;
784
						return $result;
785
						
785
 
786
						}#if end
786
						}#if end
787
						
787
 
788
					#如果只有一段內容
788
					#如果只有一段內容
789
					if($spiltString["dataCounts"]=="1"){
789
					if($spiltString["dataCounts"]=="1"){
790
						
790
 
791
						#設置錯誤識別
791
						#設置錯誤識別
792
						$result["status"]="false";
792
						$result["status"]="false";
793
						
793
 
794
						#設置錯誤訊息
794
						#設置錯誤訊息
795
						$result["error"][]="設定值字串「".$configStr."」必須要用「=」來間隔設定屬性與其數值";
795
						$result["error"][]="設定值字串「".$configStr."」必須要用「=」來間隔設定屬性與其數值";
796
						
796
 
797
						#回傳結果
797
						#回傳結果
798
						return $result;
798
						return $result;
799
						
799
 
800
						}#if end
800
						}#if end
801
						
801
 
802
					#設定暫時的設定值
802
					#設定暫時的設定值
803
					$oldConfigValue=ini_set($spiltString["dataArray"][0],$spiltString["dataArray"][1]);
803
					$oldConfigValue=ini_set($spiltString["dataArray"][0],$spiltString["dataArray"][1]);
804
					
804
 
805
					#如果設定失敗
805
					#如果設定失敗
806
					if($oldConfigValue===false){
806
					if($oldConfigValue===false){
807
						
807
 
808
						#設置錯誤識別
808
						#設置錯誤識別
809
						$result["status"]="false";
809
						$result["status"]="false";
810
						
810
 
811
						#設置錯誤訊息
811
						#設置錯誤訊息
812
						$result["error"][]="將屬性「".$spiltString["dataArray"][0]."」設定為「".$spiltString["dataArray"][1]."」失敗";
812
						$result["error"][]="將屬性「".$spiltString["dataArray"][0]."」設定為「".$spiltString["dataArray"][1]."」失敗";
813
						
813
 
814
						#回傳結果
814
						#回傳結果
815
						return $result;
815
						return $result;
816
						
816
 
817
						}#if end
817
						}#if end
818
						
818
 
819
					#反之儲存舊的永久設地數值
819
					#反之儲存舊的永久設地數值
820
					else{
820
					else{
821
						
821
 
822
						#取得舊的設定值
822
						#取得舊的設定值
823
						$result["config"][$count]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
823
						$result["config"][$count]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
824
						$result["config"][$spiltString["dataArray"][0]]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
824
						$result["config"][$spiltString["dataArray"][0]]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
825
												
825
 
826
						#取得新的設定值
826
						#取得新的設定值
827
						$result["config"][$count]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
827
						$result["config"][$count]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
828
						$result["config"][$spiltString["dataArray"][0]]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
828
						$result["config"][$spiltString["dataArray"][0]]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
829
						
829
 
830
						#計數加1
830
						#計數加1
831
						$count++;
831
						$count++;
832
						
832
 
833
						}#else end
833
						}#else end
834
					
834
 
835
					}#foreach end
835
					}#foreach end
836
								
836
 
837
				#跳出switch
837
				#跳出switch
838
				break;
838
				break;
839
			
839
 
840
			#如果不是以上狀況,那就是參數錯誤	
840
			#如果不是以上狀況,那就是參數錯誤
841
			default :
841
			default :
842
			
842
 
843
				#設置錯誤訊息
843
				#設置錯誤訊息
844
				$result["error"][]="\$conf[\"mode\"]模式設定錯誤";
844
				$result["error"][]="\$conf[\"mode\"]模式設定錯誤";
845
			
845
 
846
				#設置執行失敗
846
				#設置執行失敗
847
				$result["status"]="false";
847
				$result["status"]="false";
848
			
848
 
849
				#回傳結果
849
				#回傳結果
850
				return $result;
850
				return $result;
851
			
851
 
852
			}#switch end
852
			}#switch end
853
			
853
 
854
		#設置執行正常
854
		#設置執行正常
855
		$result["status"]="true";
855
		$result["status"]="true";
856
	
856
 
857
		#回傳結果
857
		#回傳結果
858
		return $result;
858
		return $result;
859
		
859
 
860
		}#funciton changeSettings end
860
		}#funciton changeSettings end
861
		
861
 
862
	/*
862
	/*
863
	#函式說明:
863
	#函式說明:
864
	#依照條件增加記憶體的上限.
864
	#依照條件增加記憶體的上限.
865
	#回傳結果:
865
	#回傳結果:
866
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
866
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
Line 888... Line 888...
888
	#https://www.php.net/manual/en/function.ini-set.php
888
	#https://www.php.net/manual/en/function.ini-set.php
889
	#備註:
889
	#備註:
890
	#無.
890
	#無.
891
	*/
891
	*/
892
	public static function autoAddMemory(&$conf=array()){
892
	public static function autoAddMemory(&$conf=array()){
893
	
893
 
894
		#初始化要回傳的結果
894
		#初始化要回傳的結果
895
		$result=array();
895
		$result=array();
896
 
896
 
897
		#取得當前執行的函數名稱
897
		#取得當前執行的函數名稱
898
		$result["function"]=__FUNCTION__;
898
		$result["function"]=__FUNCTION__;
899
		
899
 
900
		#取得參數
900
		#取得參數
901
		$result["argu"]=$conf;
901
		$result["argu"]=$conf;
902
 
902
 
903
		#如果 $conf 不為陣列
903
		#如果 $conf 不為陣列
904
		if(gettype($conf)!="array"){
904
		if(gettype($conf)!="array"){
Line 919... Line 919...
919
 
919
 
920
			#回傳結果
920
			#回傳結果
921
			return $result;
921
			return $result;
922
 
922
 
923
			}#if end
923
			}#if end
924
		
924
 
925
		#函式說明:
925
		#函式說明:
926
		#顯示目前的php設定值
926
		#顯示目前的php設定值
927
		#回傳的結果:
927
		#回傳的結果:
928
		#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
928
		#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
929
		#$result["error"],錯誤訊息陣列.
929
		#$result["error"],錯誤訊息陣列.
Line 941... Line 941...
941
		#http://www.php.net/manual/en/function.ini-get-all.php
941
		#http://www.php.net/manual/en/function.ini-get-all.php
942
		#備註:
942
		#備註:
943
		#無.
943
		#無.
944
		$showSettings=config::showSettings($conf["config::showSettings"]);
944
		$showSettings=config::showSettings($conf["config::showSettings"]);
945
		unset($conf["config::showSettings"]);
945
		unset($conf["config::showSettings"]);
946
		
946
 
947
		#如果執行失敗
947
		#如果執行失敗
948
		if($showSettings["status"]==="false"){
948
		if($showSettings["status"]==="false"){
949
		
949
 
950
			#設置執行失敗
950
			#設置執行失敗
951
			$result["status"]="false";
951
			$result["status"]="false";
952
			
952
 
953
			#設置錯誤資訊
953
			#設置錯誤資訊
954
			$result["error"]=$showSettings;
954
			$result["error"]=$showSettings;
955
		
955
 
956
			#回傳結果
956
			#回傳結果
957
			return $result;
957
			return $result;
958
		
958
 
959
			}#if end
959
			}#if end
960
		
960
 
961
		#取得系統設定的php記憶體上限
961
		#取得系統設定的php記憶體上限
962
		$phpMaxMemInConfig=$showSettings["content"]["memory_limit"];
962
		$phpMaxMemInConfig=$showSettings["content"]["memory_limit"];
963
		
963
 
964
		#如果單位是M
964
		#如果單位是M
965
		#函式說明:
965
		#函式說明:
966
		#取得符合特定字首與字尾的字串
966
		#取得符合特定字首與字尾的字串
967
		#回傳結果:
967
		#回傳結果:
968
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
968
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
Line 984... Line 984...
984
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
984
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
985
		#備註:
985
		#備註:
986
		#無.
986
		#無.
987
		$getMeetConditionsString=search::getMeetConditionsString($conf["stringProcess::getMeetConditionsString"]);
987
		$getMeetConditionsString=search::getMeetConditionsString($conf["stringProcess::getMeetConditionsString"]);
988
		unset($conf["stringProcess::getMeetConditionsString"]);
988
		unset($conf["stringProcess::getMeetConditionsString"]);
989
		
989
 
990
		#如果執行失敗
990
		#如果執行失敗
991
		if($getMeetConditionsString["status"]==="false"){
991
		if($getMeetConditionsString["status"]==="false"){
992
		
992
 
993
			#設置執行失敗
993
			#設置執行失敗
994
			$result["status"]="false";
994
			$result["status"]="false";
995
			
995
 
996
			#設置錯誤資訊
996
			#設置錯誤資訊
997
			$result["error"]=$getMeetConditionsString;
997
			$result["error"]=$getMeetConditionsString;
998
		
998
 
999
			#回傳結果
999
			#回傳結果
1000
			return $result;
1000
			return $result;
1001
		
1001
 
1002
			}#if end
1002
			}#if end
1003
			
1003
 
1004
		#如果是M結尾
1004
		#如果是M結尾
1005
		if($getMeetConditionsString["founded"]==="true"){
1005
		if($getMeetConditionsString["founded"]==="true"){
1006
		
1006
 
1007
			#轉換為bytes
1007
			#轉換為bytes
1008
			$phpMaxMemInConfig=$getMeetConditionsString["content"]*1024*1024;
1008
			$phpMaxMemInConfig=$getMeetConditionsString["content"]*1024*1024;
1009
		
1009
 
1010
			}#if end
1010
			}#if end
1011
				
1011
 
1012
		#函式說明:
1012
		#函式說明:
1013
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
1013
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
1014
		#回傳結果:
1014
		#回傳結果:
1015
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1015
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1016
		#$result["error"],執行不正常結束的錯訊息陣列.
1016
		#$result["error"],執行不正常結束的錯訊息陣列.
Line 1059... Line 1059...
1059
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1059
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1060
		#備註:
1060
		#備註:
1061
		#無.
1061
		#無.
1062
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1062
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1063
		unset($conf["variableCheck::checkArguments"]);
1063
		unset($conf["variableCheck::checkArguments"]);
1064
		
1064
 
1065
		#如果執行失敗
1065
		#如果執行失敗
1066
		if($checkArguments["status"]==="false"){
1066
		if($checkArguments["status"]==="false"){
1067
		
1067
 
1068
			#設置執行失敗
1068
			#設置執行失敗
1069
			$result["status"]="false";
1069
			$result["status"]="false";
1070
 
1070
 
1071
			#設置執行錯誤訊息
1071
			#設置執行錯誤訊息
1072
			$result["error"]=$checkArguments;
1072
			$result["error"]=$checkArguments;
1073
			
1073
 
1074
			#回傳結果
1074
			#回傳結果
1075
			return $result;
1075
			return $result;
1076
		
1076
 
1077
			}#if end
1077
			}#if end
1078
			
1078
 
1079
		#如果檢查不通過
1079
		#如果檢查不通過
1080
		if($checkArguments["passed"]==="false"){
1080
		if($checkArguments["passed"]==="false"){
1081
		
1081
 
1082
			#設置執行失敗
1082
			#設置執行失敗
1083
			$result["status"]="false";
1083
			$result["status"]="false";
1084
 
1084
 
1085
			#設置執行錯誤訊息
1085
			#設置執行錯誤訊息
1086
			$result["error"]=$checkArguments;
1086
			$result["error"]=$checkArguments;
1087
			
1087
 
1088
			#回傳結果
1088
			#回傳結果
1089
			return $result;
1089
			return $result;
1090
		
1090
 
1091
			}#if end
1091
			}#if end
1092
		
1092
 
1093
		#如果有 serverCache
1093
		#如果有 serverCache
1094
		if(isset($conf["serverCache"])){
1094
		if(isset($conf["serverCache"])){
1095
		
1095
 
1096
			/* debug
1096
			/* debug
1097
			
1097
 
1098
			#函式說明:
1098
			#函式說明:
1099
			#撰寫log
1099
			#撰寫log
1100
			#回傳結果:
1100
			#回傳結果:
1101
			#$result["status"],狀態,"true"或"false".
1101
			#$result["status"],狀態,"true"或"false".
1102
			#$result["error"],錯誤訊息陣列.
1102
			#$result["error"],錯誤訊息陣列.
Line 1119... Line 1119...
1119
			#無.
1119
			#無.
1120
			#備註:
1120
			#備註:
1121
			#無.
1121
			#無.
1122
			$record=logs::record($conf["logs::record"]);
1122
			$record=logs::record($conf["logs::record"]);
1123
			unset($conf["logs::record"]);
1123
			unset($conf["logs::record"]);
1124
												
1124
 
1125
			#如果執行失敗
1125
			#如果執行失敗
1126
			if($record["status"]==="false"){
1126
			if($record["status"]==="false"){
1127
			
1127
 
1128
				#設置執行錯誤識別
1128
				#設置執行錯誤識別
1129
				$result["status"]="false";
1129
				$result["status"]="false";
1130
			
1130
 
1131
				#設置執行錯誤
1131
				#設置執行錯誤
1132
				$result["error"]=$record;
1132
				$result["error"]=$record;
1133
			
1133
 
1134
				#回傳結果
1134
				#回傳結果
1135
				return $result;
1135
				return $result;
1136
			
1136
 
1137
				}#if end
1137
				}#if end
1138
			
1138
 
1139
			*/
1139
			*/
1140
		
1140
 
1141
			#記錄回傳的參考
1141
			#記錄回傳的參考
1142
			#$result["cache"]=&$result;
1142
			#$result["cache"]=&$result;
1143
		
1143
 
1144
			#如果有 clientSide
1144
			#如果有 clientSide
1145
			if(isset($conf["serverCache"]["clientSide"])){
1145
			if(isset($conf["serverCache"]["clientSide"])){
1146
				
1146
 
1147
				#如果有 addOnProcessFunc
1147
				#如果有 addOnProcessFunc
1148
				if(isset($conf["serverCache"]["clientSide"]["addOnProcessFunc"])){
1148
				if(isset($conf["serverCache"]["clientSide"]["addOnProcessFunc"])){
1149
				
1149
 
1150
					#如果有 addOnProcessFuncForUnixDomainSockServerInRunWithAutoAddMemoryDaemon
1150
					#如果有 addOnProcessFuncForUnixDomainSockServerInRunWithAutoAddMemoryDaemon
1151
					if(isset($conf["serverCache"]["clientSide"]["addOnProcessFunc"]["\qbpwcf\sock::addOnProcessFuncForUnixDomainSockServerInRunWithAutoAddMemoryDaemon"])){
1151
					if(isset($conf["serverCache"]["clientSide"]["addOnProcessFunc"]["\qbpwcf\sock::addOnProcessFuncForUnixDomainSockServerInRunWithAutoAddMemoryDaemon"])){
1152
					
1152
 
1153
						/* debug
1153
						/* debug
1154
									
1154
 
1155
						#函式說明:
1155
						#函式說明:
1156
						#撰寫log
1156
						#撰寫log
1157
						#回傳結果:
1157
						#回傳結果:
1158
						#$result["status"],狀態,"true"或"false".
1158
						#$result["status"],狀態,"true"或"false".
1159
						#$result["error"],錯誤訊息陣列.
1159
						#$result["error"],錯誤訊息陣列.
Line 1176... Line 1176...
1176
						#無.
1176
						#無.
1177
						#備註:
1177
						#備註:
1178
						#無.
1178
						#無.
1179
						$record=logs::record($conf["logs::record"]);
1179
						$record=logs::record($conf["logs::record"]);
1180
						unset($conf["logs::record"]);
1180
						unset($conf["logs::record"]);
1181
															
1181
 
1182
						#如果執行失敗
1182
						#如果執行失敗
1183
						if($record["status"]==="false"){
1183
						if($record["status"]==="false"){
1184
						
1184
 
1185
							#設置執行錯誤識別
1185
							#設置執行錯誤識別
1186
							$result["status"]="false";
1186
							$result["status"]="false";
1187
						
1187
 
1188
							#設置執行錯誤
1188
							#設置執行錯誤
1189
							$result["error"]=$record;
1189
							$result["error"]=$record;
1190
						
1190
 
1191
							#回傳結果
1191
							#回傳結果
1192
							return $result;
1192
							return $result;
1193
						
1193
 
1194
							}#if end
1194
							}#if end
1195
						
1195
 
1196
						*/
1196
						*/
1197
					
1197
 
1198
						#如果有程式在背景執行
1198
						#如果有程式在背景執行
1199
						if(isset($conf["serverCache"]["clientSide"]["addOnProcessFunc"]["\qbpwcf\sock::addOnProcessFuncForUnixDomainSockServerInRunWithAutoAddMemoryDaemon"]["content"])){
1199
						if(isset($conf["serverCache"]["clientSide"]["addOnProcessFunc"]["\qbpwcf\sock::addOnProcessFuncForUnixDomainSockServerInRunWithAutoAddMemoryDaemon"]["content"])){
1200
						
1200
 
1201
							#如果該程序資訊存在
1201
							#如果該程序資訊存在
1202
							if(isset($conf["serverCache"]["clientSide"]["addOnProcessFunc"]["\qbpwcf\sock::addOnProcessFuncForUnixDomainSockServerInRunWithAutoAddMemoryDaemon"]["content"][0])){
1202
							if(isset($conf["serverCache"]["clientSide"]["addOnProcessFunc"]["\qbpwcf\sock::addOnProcessFuncForUnixDomainSockServerInRunWithAutoAddMemoryDaemon"]["content"][0])){
1203
									
1203
 
1204
								#另存程序變數參考
1204
								#另存程序變數參考
1205
								$process=&$conf["serverCache"]["clientSide"]["addOnProcessFunc"]["\qbpwcf\sock::addOnProcessFuncForUnixDomainSockServerInRunWithAutoAddMemoryDaemon"]["content"][0];
1205
								$process=&$conf["serverCache"]["clientSide"]["addOnProcessFunc"]["\qbpwcf\sock::addOnProcessFuncForUnixDomainSockServerInRunWithAutoAddMemoryDaemon"]["content"][0];
1206
								
1206
 
1207
								/* debug
1207
								/* debug
1208
									
1208
 
1209
								#函式說明:
1209
								#函式說明:
1210
								#撰寫log
1210
								#撰寫log
1211
								#回傳結果:
1211
								#回傳結果:
1212
								#$result["status"],狀態,"true"或"false".
1212
								#$result["status"],狀態,"true"或"false".
1213
								#$result["error"],錯誤訊息陣列.
1213
								#$result["error"],錯誤訊息陣列.
Line 1230... Line 1230...
1230
								#無.
1230
								#無.
1231
								#備註:
1231
								#備註:
1232
								#無.
1232
								#無.
1233
								$record=logs::record($conf["logs::record"]);
1233
								$record=logs::record($conf["logs::record"]);
1234
								unset($conf["logs::record"]);
1234
								unset($conf["logs::record"]);
1235
																	
-
 
-
 
1235
 
1236
								#如果執行失敗
1236
								#如果執行失敗
1237
								if($record["status"]==="false"){
1237
								if($record["status"]==="false"){
1238
								
1238
 
1239
									#設置執行錯誤識別
1239
									#設置執行錯誤識別
1240
									$result["status"]="false";
1240
									$result["status"]="false";
1241
								
1241
 
1242
									#設置執行錯誤
1242
									#設置執行錯誤
1243
									$result["error"]=$record;
1243
									$result["error"]=$record;
1244
								
1244
 
1245
									#回傳結果
1245
									#回傳結果
1246
									return $result;
1246
									return $result;
1247
								
1247
 
1248
									}#if end
1248
									}#if end
1249
								
1249
 
1250
								*/
1250
								*/
1251
								
1251
 
1252
								#取得標準輸出
1252
								#取得標準輸出
1253
								$result["stdout"]=$process["content"];
1253
								$result["stdout"]=$process["content"];
1254
								
1254
 
1255
								#取得非標準輸出
1255
								#取得非標準輸出
1256
								$result["error"]=$process["error"];
1256
								$result["error"]=$process["error"];
1257
								
1257
 
1258
								#如果標準輸出是 reource
1258
								#如果標準輸出是 reource
1259
								if(gettype($process["content"])==="resource"){
1259
								if(gettype($process["content"])==="resource"){
1260
								
1260
 
1261
									#取得程式執行過程產生的標準輸出
1261
									#取得程式執行過程產生的標準輸出
1262
									$result["stdout"]=stream_get_contents($process["content"]);
1262
									$result["stdout"]=stream_get_contents($process["content"]);
1263
									
1263
 
1264
									}#if end
1264
									}#if end
1265
								
1265
 
1266
								#如果非標準輸出是 reource
1266
								#如果非標準輸出是 reource
1267
								if(gettype($process["error"])==="resource"){
1267
								if(gettype($process["error"])==="resource"){
1268
									
1268
 
1269
									#取得程式執行過程產生的標準輸出
1269
									#取得程式執行過程產生的標準輸出
1270
									$result["error"]=stream_get_contents($process["error"]);
1270
									$result["error"]=stream_get_contents($process["error"]);
1271
									
1271
 
1272
									}#if end
1272
									}#if end
1273
									
1273
 
1274
								#如果記錄上顯示該程序尚在執行中
1274
								#如果記錄上顯示該程序尚在執行中
1275
								if($process["proc_get_status"]["running"]===true){
1275
								if($process["proc_get_status"]["running"]===true){
1276
								
1276
 
1277
									#嘗試取得該程序的狀態
1277
									#嘗試取得該程序的狀態
1278
									$proc_get_status=proc_get_status($process["process"]);
1278
									$proc_get_status=proc_get_status($process["process"]);
1279
								
1279
 
1280
									#如果已經結束執行
1280
									#如果已經結束執行
1281
									if($proc_get_status["running"]===false){
1281
									if($proc_get_status["running"]===false){
1282
									
1282
 
1283
										#設置要結束執行unix domain server
1283
										#設置要結束執行unix domain server
1284
										$result["exit"]="true";
1284
										$result["exit"]="true";
1285
										
1285
 
1286
										#設置執行正常
1286
										#設置執行正常
1287
										$result["status"]="true";
1287
										$result["status"]="true";
1288
										
1288
 
1289
										}#if end
1289
										}#if end
1290
									
1290
 
1291
									}#if end
1291
									}#if end
1292
									
1292
 
1293
								#反之代表程序已經結束
1293
								#反之代表程序已經結束
1294
								else{
1294
								else{
1295
								
1295
 
1296
									#設置要結束執行unix domain server
1296
									#設置要結束執行unix domain server
1297
									$result["exit"]="true";
1297
									$result["exit"]="true";
1298
									
1298
 
1299
									#設置執行正常
1299
									#設置執行正常
1300
									$result["status"]="true";
1300
									$result["status"]="true";
1301
									
1301
 
1302
									}#else end
1302
									}#else end
1303
								
1303
 
1304
								/* debug
1304
								/* debug
1305
									
1305
 
1306
								#函式說明:
1306
								#函式說明:
1307
								#撰寫log
1307
								#撰寫log
1308
								#回傳結果:
1308
								#回傳結果:
1309
								#$result["status"],狀態,"true"或"false".
1309
								#$result["status"],狀態,"true"或"false".
1310
								#$result["error"],錯誤訊息陣列.
1310
								#$result["error"],錯誤訊息陣列.
Line 1327... Line 1327...
1327
								#無.
1327
								#無.
1328
								#備註:
1328
								#備註:
1329
								#無.
1329
								#無.
1330
								$record=logs::record($conf["logs::record"]);
1330
								$record=logs::record($conf["logs::record"]);
1331
								unset($conf["logs::record"]);
1331
								unset($conf["logs::record"]);
1332
																	
-
 
-
 
1332
 
1333
								#如果執行失敗
1333
								#如果執行失敗
1334
								if($record["status"]==="false"){
1334
								if($record["status"]==="false"){
1335
								
1335
 
1336
									#設置執行錯誤識別
1336
									#設置執行錯誤識別
1337
									$result["status"]="false";
1337
									$result["status"]="false";
1338
								
1338
 
1339
									#設置執行錯誤
1339
									#設置執行錯誤
1340
									$result["error"]=$record;
1340
									$result["error"]=$record;
1341
								
1341
 
1342
									#回傳結果
1342
									#回傳結果
1343
									return $result;
1343
									return $result;
1344
								
1344
 
1345
									}#if end
1345
									}#if end
1346
								
1346
 
1347
								*/
1347
								*/
1348
								
1348
 
1349
								}#if end
1349
								}#if end
1350
						
1350
 
1351
							}#if end
1351
							}#if end
1352
					
1352
 
1353
						}#if end
1353
						}#if end
1354
				
1354
 
1355
					}#if end
1355
					}#if end
1356
			
1356
 
1357
				}#if end
1357
				}#if end
1358
		
1358
 
1359
			}#if end
1359
			}#if end
1360
		
1360
 
1361
		#如果參數 whenAviMemLessThan 不為 
1361
		#如果參數 whenAviMemLessThan 不為
1362
		$whenAviMemLessThan=(int)($conf["whenAviMemLessThan"]);
1362
		$whenAviMemLessThan=(int)($conf["whenAviMemLessThan"]);
1363
		
1363
 
1364
		#如果小於1
1364
		#如果小於1
1365
		if($whenAviMemLessThan<1){
1365
		if($whenAviMemLessThan<1){
1366
		
1366
 
1367
			#設置為1
1367
			#設置為1
1368
			$whenAviMemLessThan=1;
1368
			$whenAviMemLessThan=1;
1369
		
1369
 
1370
			}#if end
1370
			}#if end
1371
			
1371
 
1372
		#如果大於50
1372
		#如果大於50
1373
		else if($whenAviMemLessThan>50){
1373
		else if($whenAviMemLessThan>50){
1374
		
1374
 
1375
			#設置為50
1375
			#設置為50
1376
			$whenAviMemLessThan=50;
1376
			$whenAviMemLessThan=50;
1377
		
1377
 
1378
			}#if end
1378
			}#if end
1379
		
1379
 
1380
		#計算需要增加記憶體的門檻
1380
		#計算需要增加記憶體的門檻
1381
		$condition=$phpMaxMemInConfig*$whenAviMemLessThan/100;
1381
		$condition=$phpMaxMemInConfig*$whenAviMemLessThan/100;
1382
			
1382
 
1383
		#get memeory usage
1383
		#get memeory usage
1384
		$memUsedInBytes=\memory_get_usage();
1384
		$memUsedInBytes=\memory_get_usage();
1385
		
1385
 
1386
		#如果使用的記憶體已經達到門檻
1386
		#如果使用的記憶體已經達到門檻
1387
		if($memUsedInBytes>=$condition){
1387
		if($memUsedInBytes>=$condition){
1388
		
1388
 
1389
			#計算新的記憶體上限
1389
			#計算新的記憶體上限
1390
			$newMemoryLimit=$phpMaxMemInConfig+$stepAmount;
1390
			$newMemoryLimit=$phpMaxMemInConfig+$stepAmount;
1391
		
1391
 
1392
			#依照 stepAmount 來增加可用記憶體的上限
1392
			#依照 stepAmount 來增加可用記憶體的上限
1393
			$return=\ini_set("memory_limit",$stepAmount);
1393
			$return=\ini_set("memory_limit",$stepAmount);
1394
		
1394
 
1395
			#如果設置失敗
1395
			#如果設置失敗
1396
			if($return===false){
1396
			if($return===false){
1397
			
1397
 
1398
				#設置執行失敗
1398
				#設置執行失敗
1399
				$result["status"]="false";
1399
				$result["status"]="false";
1400
 
1400
 
1401
				#設置執行錯誤訊息
1401
				#設置執行錯誤訊息
1402
				$result["error"][]="加大記憶體上限失敗";
1402
				$result["error"][]="加大記憶體上限失敗";
1403
				
1403
 
1404
				#cache
1404
				#cache
1405
				$result["cache"]=&$result;
1405
				$result["cache"]=&$result;
1406
				
1406
 
1407
				#回傳結果
1407
				#回傳結果
1408
				return $result;
1408
				return $result;
1409
			
1409
 
1410
				}#if end
1410
				}#if end
1411
				
1411
 
1412
			#設置正常訊息
1412
			#設置正常訊息
1413
			$result["content"]="memeory_limit changed from ".$return." to ".$newMemoryLimit;
1413
			$result["content"]="memeory_limit changed from ".$return." to ".$newMemoryLimit;
1414
					
1414
 
1415
			}#if end
1415
			}#if end
1416
			
1416
 
1417
		#提示未改變
1417
		#提示未改變
1418
		$result["content"]="memeory_limit not changed";	
1418
		$result["content"]="memeory_limit not changed";
1419
			
1419
 
1420
		#設置執行正常
1420
		#設置執行正常
1421
		$result["status"]="true";
1421
		$result["status"]="true";
1422
		
1422
 
1423
		#cache
1423
		#cache
1424
		$result["cache"]=&$result;
1424
		$result["cache"]=&$result;
1425
		
1425
 
1426
		#回傳結果
1426
		#回傳結果
1427
		return $result;
1427
		return $result;
1428
		
1428
 
1429
		}#function autoAddMemory end
1429
		}#function autoAddMemory end
1430
	
1430
 
1431
	/*
1431
	/*
1432
	#函式說明:
1432
	#函式說明:
1433
	#建立供 apache 讀取的設定檔案.
1433
	#建立供 apache 讀取的設定檔案.
1434
	#回傳結果:
1434
	#回傳結果:
1435
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
1435
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
Line 1450... Line 1450...
1450
	#無.
1450
	#無.
1451
	#備註:
1451
	#備註:
1452
	#檔案內容的格式為多行json編碼然後url編碼然後base64編碼後的內容,每行代表一組定義.每組定義的json格式為php多維陣列所組成.
1452
	#檔案內容的格式為多行json編碼然後url編碼然後base64編碼後的內容,每行代表一組定義.每組定義的json格式為php多維陣列所組成.
1453
	*/
1453
	*/
1454
	public static function create(&$conf=array()){
1454
	public static function create(&$conf=array()){
1455
	
1455
 
1456
		#初始化要回傳的結果
1456
		#初始化要回傳的結果
1457
		$result=array();
1457
		$result=array();
1458
 
1458
 
1459
		#儲存當前執行的函數
1459
		#儲存當前執行的函數
1460
		$result["function"]=__FUNCTION__;
1460
		$result["function"]=__FUNCTION__;
1461
 
1461
 
1462
		#如果 $conf 不為陣列
1462
		#如果 $conf 不為陣列
1463
		if(gettype($conf)!="array"){
1463
		if(gettype($conf)!="array"){
1464
			
1464
 
1465
			#設置執行失敗
1465
			#設置執行失敗
1466
			$result["status"]="false";
1466
			$result["status"]="false";
1467
			
1467
 
1468
			#設置執行錯誤訊息
1468
			#設置執行錯誤訊息
1469
			$result["error"][]="\$conf變數須為陣列形態";
1469
			$result["error"][]="\$conf變數須為陣列形態";
1470
 
1470
 
1471
			#如果傳入的參數為 null
1471
			#如果傳入的參數為 null
1472
			if($conf==null){
1472
			if($conf==null){
1473
				
1473
 
1474
				#設置執行錯誤訊息
1474
				#設置執行錯誤訊息
1475
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1475
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1476
				
1476
 
1477
				}#if end
1477
				}#if end
1478
 
1478
 
1479
			#回傳結果
1479
			#回傳結果
1480
			return $result;
1480
			return $result;
1481
	
1481
 
1482
			}#if end
1482
			}#if end
1483
	
1483
 
1484
		#檢查參數
1484
		#檢查參數
1485
		#函式說明:
1485
		#函式說明:
1486
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1486
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1487
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1487
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1488
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1488
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 1497... Line 1497...
1497
		#必填寫的參數:
1497
		#必填寫的參數:
1498
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1498
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1499
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1499
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1500
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1500
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1501
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","configFileAddr","content");
1501
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","configFileAddr","content");
1502
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
1502
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
1503
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array");
1503
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array");
1504
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1504
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1505
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1505
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1506
		#可以省略的參數:
1506
		#可以省略的參數:
1507
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1507
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1508
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1508
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1509
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1509
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1510
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
1510
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
1511
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
1511
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
1512
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
1512
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
1513
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1513
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1514
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
1514
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
1515
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1515
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1516
		#$conf["arrayCountEqualCheck"][]=array();
1516
		#$conf["arrayCountEqualCheck"][]=array();
1517
		#參考資料來源:
1517
		#參考資料來源:
1518
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1518
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1519
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1519
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1520
		unset($conf["variableCheck::checkArguments"]);
1520
		unset($conf["variableCheck::checkArguments"]);
1521
	
1521
 
1522
		#如果檢查失敗
1522
		#如果檢查失敗
1523
		if($checkArguments["status"]=="false"){
1523
		if($checkArguments["status"]=="false"){
1524
			
1524
 
1525
			#設置錯誤識別
1525
			#設置錯誤識別
1526
			$result["status"]="false";
1526
			$result["status"]="false";
1527
			
1527
 
1528
			#設置錯誤訊息
1528
			#設置錯誤訊息
1529
			$result["error"]=$checkArguments;
1529
			$result["error"]=$checkArguments;
1530
			
1530
 
1531
			#回傳結果
1531
			#回傳結果
1532
			return $result;
1532
			return $result;
1533
			
1533
 
1534
			}#if end
1534
			}#if end
1535
	
1535
 
1536
		#如果檢查不通過
1536
		#如果檢查不通過
1537
		if($checkArguments["passed"]=="false"){
1537
		if($checkArguments["passed"]=="false"){
1538
			
1538
 
1539
			#設置錯誤識別
1539
			#設置錯誤識別
1540
			$result["status"]="false";
1540
			$result["status"]="false";
1541
			
1541
 
1542
			#設置錯誤訊息
1542
			#設置錯誤訊息
1543
			$result["error"]=$checkArguments;
1543
			$result["error"]=$checkArguments;
1544
			
1544
 
1545
			#回傳結果
1545
			#回傳結果
1546
			return $result;
1546
			return $result;
1547
			
1547
 
1548
			}#if end
1548
			}#if end
1549
			
1549
 
1550
		#debug
1550
		#debug
1551
		#var_dump($conf["content"]);exit;	
1551
		#var_dump($conf["content"]);exit;
1552
			
1552
 
1553
		#函式說明:
1553
		#函式說明:
1554
		#將字串寫入到檔案
1554
		#將字串寫入到檔案
1555
		#回傳結果:
1555
		#回傳結果:
1556
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1556
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1557
		#$result["error"],錯誤訊息陣列.
1557
		#$result["error"],錯誤訊息陣列.
Line 1583... Line 1583...
1583
		#無.
1583
		#無.
1584
		#備註:
1584
		#備註:
1585
		#無.
1585
		#無.
1586
		$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
1586
		$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
1587
		unset($conf["fileAccess::writeTextIntoFile"]);
1587
		unset($conf["fileAccess::writeTextIntoFile"]);
1588
	
1588
 
1589
		#如果執行敗
1589
		#如果執行敗
1590
		if($writeTextIntoFile["status"]=="false"){
1590
		if($writeTextIntoFile["status"]=="false"){
1591
			
1591
 
1592
			#設置錯誤識別
1592
			#設置錯誤識別
1593
			$result["status"]="false";
1593
			$result["status"]="false";
1594
			
1594
 
1595
			#設置錯誤訊息
1595
			#設置錯誤訊息
1596
			$result["error"]=$writeTextIntoFile;
1596
			$result["error"]=$writeTextIntoFile;
1597
			
1597
 
1598
			#回傳結果
1598
			#回傳結果
1599
			return $result;
1599
			return $result;
1600
			
1600
 
1601
			}#if end
1601
			}#if end
1602
	
1602
 
1603
		#設置定義正常
1603
		#設置定義正常
1604
		$result["status"]="true";
1604
		$result["status"]="true";
1605
	
1605
 
1606
		#回傳結果
1606
		#回傳結果
1607
		return $result;
1607
		return $result;
1608
	
1608
 
1609
		}#function create end
1609
		}#function create end
1610
	
1610
 
1611
	/*
1611
	/*
1612
	#函式說明:
1612
	#函式說明:
1613
	#提供post的變數查尋定義檔,給予回應.
1613
	#提供post的變數查尋定義檔,給予回應.
1614
	#回傳結果:
1614
	#回傳結果:
1615
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
1615
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
Line 1630... Line 1630...
1630
	#無.
1630
	#無.
1631
	#備註:
1631
	#備註:
1632
	#檔案內容的格式為多行json編碼然後url編碼然後base64編碼後的內容,每行代表一組定義.每組定義的json格式為php多維陣列所組成.
1632
	#檔案內容的格式為多行json編碼然後url編碼然後base64編碼後的內容,每行代表一組定義.每組定義的json格式為php多維陣列所組成.
1633
	*/
1633
	*/
1634
	public static function server(&$conf=array()){
1634
	public static function server(&$conf=array()){
1635
	
1635
 
1636
		#初始化要回傳的結果
1636
		#初始化要回傳的結果
1637
		$result=array();
1637
		$result=array();
1638
 
1638
 
1639
		#儲存當前執行的函數
1639
		#儲存當前執行的函數
1640
		$result["function"]=__FUNCTION__;
1640
		$result["function"]=__FUNCTION__;
1641
 
1641
 
1642
		#如果 $conf 不為陣列
1642
		#如果 $conf 不為陣列
1643
		if(gettype($conf)!="array"){
1643
		if(gettype($conf)!="array"){
1644
			
1644
 
1645
			#設置執行失敗
1645
			#設置執行失敗
1646
			$result["status"]="false";
1646
			$result["status"]="false";
1647
			
1647
 
1648
			#設置執行錯誤訊息
1648
			#設置執行錯誤訊息
1649
			$result["error"][]="\$conf變數須為陣列形態";
1649
			$result["error"][]="\$conf變數須為陣列形態";
1650
 
1650
 
1651
			#如果傳入的參數為 null
1651
			#如果傳入的參數為 null
1652
			if($conf==null){
1652
			if($conf==null){
1653
				
1653
 
1654
				#設置執行錯誤訊息
1654
				#設置執行錯誤訊息
1655
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1655
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1656
				
1656
 
1657
				}#if end
1657
				}#if end
1658
 
1658
 
1659
			#回傳結果
1659
			#回傳結果
1660
			return $result;
1660
			return $result;
1661
	
1661
 
1662
			}#if end
1662
			}#if end
1663
	
1663
 
1664
		#記錄所使用的參數
1664
		#記錄所使用的參數
1665
		$result["argu"]=$conf;
1665
		$result["argu"]=$conf;
1666
	
1666
 
1667
		#檢查參數
1667
		#檢查參數
1668
		#函式說明:
1668
		#函式說明:
1669
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1669
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1670
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1670
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1671
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1671
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 1680... Line 1680...
1680
		#必填寫的參數:
1680
		#必填寫的參數:
1681
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1681
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1682
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1682
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1683
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1683
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1684
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","configFileAddr");
1684
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","configFileAddr");
1685
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
1685
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
1686
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string",null);
1686
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string",null);
1687
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1687
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1688
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1688
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1689
		#可以省略的參數:
1689
		#可以省略的參數:
1690
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1690
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1691
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1691
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1692
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1692
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1693
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
1693
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
1694
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
1694
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
1695
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
1695
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
1696
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1696
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1697
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
1697
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
1698
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1698
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1699
		#$conf["arrayCountEqualCheck"][]=array();
1699
		#$conf["arrayCountEqualCheck"][]=array();
1700
		#參考資料來源:
1700
		#參考資料來源:
1701
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1701
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1702
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1702
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1703
		unset($conf["variableCheck::checkArguments"]);
1703
		unset($conf["variableCheck::checkArguments"]);
1704
	
1704
 
1705
		#如果檢查失敗
1705
		#如果檢查失敗
1706
		if($checkArguments["status"]=="false"){
1706
		if($checkArguments["status"]=="false"){
1707
			
1707
 
1708
			#設置錯誤識別
1708
			#設置錯誤識別
1709
			$result["status"]="false";
1709
			$result["status"]="false";
1710
			
1710
 
1711
			#設置錯誤訊息
1711
			#設置錯誤訊息
1712
			$result["error"]=$checkArguments;
1712
			$result["error"]=$checkArguments;
1713
			
1713
 
1714
			#回傳結果
1714
			#回傳結果
1715
			return $result;
1715
			return $result;
1716
			
1716
 
1717
			}#if end
1717
			}#if end
1718
	
1718
 
1719
		#如果檢查不通過
1719
		#如果檢查不通過
1720
		if($checkArguments["passed"]=="false"){
1720
		if($checkArguments["passed"]=="false"){
1721
			
1721
 
1722
			#設置錯誤識別
1722
			#設置錯誤識別
1723
			$result["status"]="false";
1723
			$result["status"]="false";
1724
			
1724
 
1725
			#設置錯誤訊息
1725
			#設置錯誤訊息
1726
			$result["error"]=$checkArguments;
1726
			$result["error"]=$checkArguments;
1727
			
1727
 
1728
			#回傳結果
1728
			#回傳結果
1729
			return $result;
1729
			return $result;
1730
			
1730
 
1731
			}#if end
1731
			}#if end
1732
	
1732
 
1733
		#debug
1733
		#debug
1734
		#var_dump($checkArguments);exit;
1734
		#var_dump($checkArguments);exit;
1735
		
1735
 
1736
		#儲存key的結構
1736
		#儲存key的結構
1737
		$keys=array();
1737
		$keys=array();
1738
		
1738
 
1739
		#如果沒有 post 變數存在
1739
		#如果沒有 post 變數存在
1740
		if(count($_POST)<1){
1740
		if(count($_POST)<1){
1741
		
1741
 
1742
			#設置錯誤識別
1742
			#設置錯誤識別
1743
			$result["status"]="false";
1743
			$result["status"]="false";
1744
			
1744
 
1745
			#設置錯誤訊息
1745
			#設置錯誤訊息
1746
			$result["error"][]="沒有post變數";
1746
			$result["error"][]="沒有post變數";
1747
			
1747
 
1748
			#回傳結果
1748
			#回傳結果
1749
			return $result;
1749
			return $result;
1750
		
1750
 
1751
			}#if end
1751
			}#if end
1752
		
1752
 
1753
		#debug
1753
		#debug
1754
		#var_dump($_POST);exit;
1754
		#var_dump($_POST);exit;
1755
		
1755
 
1756
		#取得第一層key
1756
		#取得第一層key
1757
		$layer=array_keys($_POST)[0];
1757
		$layer=array_keys($_POST)[0];
1758
		
1758
 
1759
		#取得數值內容
1759
		#取得數值內容
1760
		$values=$_POST[$layer];
1760
		$values=$_POST[$layer];
1761
		
1761
 
1762
		#如果該層級內容形態是陣列
1762
		#如果該層級內容形態是陣列
1763
		while(gettype($values)==="array"){
1763
		while(gettype($values)==="array"){
1764
		
1764
 
1765
			#抓取查尋的key結構
1765
			#抓取查尋的key結構
1766
			$keys[]=$layer;
1766
			$keys[]=$layer;
1767
			
1767
 
1768
			#取得新層級的key
1768
			#取得新層級的key
1769
			$layer=array_keys($values)[0];
1769
			$layer=array_keys($values)[0];
1770
			
1770
 
1771
			#取得新的內容
1771
			#取得新的內容
1772
			$values=$values[$layer];
1772
			$values=$values[$layer];
1773
			
1773
 
1774
			}#while end
1774
			}#while end
1775
			
1775
 
1776
		#取得最後一層的key
1776
		#取得最後一層的key
1777
		$keys[]=$layer;
1777
		$keys[]=$layer;
1778
		
1778
 
1779
		#debug
1779
		#debug
1780
		#var_dump($keys);exit;
1780
		#var_dump($keys);exit;
1781
		
1781
 
1782
		#設置預設的定義內容
1782
		#設置預設的定義內容
1783
		$result["content"]="undefined";
1783
		$result["content"]="undefined";
1784
	
1784
 
1785
		#如果configFileAddr是字串
1785
		#如果configFileAddr是字串
1786
		if(gettype($conf["configFileAddr"])==="string"){
1786
		if(gettype($conf["configFileAddr"])==="string"){
1787
		
1787
 
1788
			#代表為檔案位置
1788
			#代表為檔案位置
1789
			
1789
 
1790
			#函式說明:
1790
			#函式說明:
1791
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1791
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1792
			#回傳的變數說明:
1792
			#回傳的變數說明:
1793
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1793
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1794
			#$result["error"],錯誤訊息提示.
1794
			#$result["error"],錯誤訊息提示.
Line 1812... Line 1812...
1812
			#file=>http:#php.net/manual/en/function.file.php
1812
			#file=>http:#php.net/manual/en/function.file.php
1813
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
1813
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
1814
			#filesize=>http://php.net/manual/en/function.filesize.php
1814
			#filesize=>http://php.net/manual/en/function.filesize.php
1815
			$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
1815
			$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
1816
			unset($conf["fileAccess::getFileContent"]);
1816
			unset($conf["fileAccess::getFileContent"]);
1817
			
1817
 
1818
			#如果讀取檔案失敗
1818
			#如果讀取檔案失敗
1819
			if($getFileContent["status"]==="false"){
1819
			if($getFileContent["status"]==="false"){
1820
			
1820
 
1821
				#設置錯誤識別
1821
				#設置錯誤識別
1822
				$result["status"]="false";
1822
				$result["status"]="false";
1823
				
1823
 
1824
				#設置錯誤訊息
1824
				#設置錯誤訊息
1825
				$result["error"]=$getFileContent;
1825
				$result["error"]=$getFileContent;
1826
				
1826
 
1827
				#回傳結果
1827
				#回傳結果
1828
				return $result;
1828
				return $result;
1829
			
1829
 
1830
				}#if end
1830
				}#if end
1831
			
1831
 
1832
			#debug
1832
			#debug
1833
			#var_dump($getFileContent);
1833
			#var_dump($getFileContent);
1834
			#var_dump(base64_decode($getFileContent));
1834
			#var_dump(base64_decode($getFileContent));
1835
			#var_dump(urldecode(base64_decode($getFileContent)));
1835
			#var_dump(urldecode(base64_decode($getFileContent)));
1836
			#var_dump(json_decode(urldecode(base64_decode($getFileContent))));
1836
			#var_dump(json_decode(urldecode(base64_decode($getFileContent))));
1837
			#exit;
1837
			#exit;
1838
			
1838
 
1839
			#針對每行
1839
			#針對每行
1840
			foreach($getFileContent["fileContent"] as $line){
1840
			foreach($getFileContent["fileContent"] as $line){
1841
			
1841
 
1842
				#解析內容
1842
				#解析內容
1843
				$def=(array)json_decode(urldecode(base64_decode($line)));
1843
				$def=(array)json_decode(urldecode(base64_decode($line)));
1844
					
1844
 
1845
				#debug
1845
				#debug
1846
				#var_dump($def);exit;
1846
				#var_dump($def);exit;
1847
				#var_dump($keys[$i]);exit;
1847
				#var_dump($keys[$i]);exit;
1848
					
1848
 
1849
				#初始化要找到的層級
1849
				#初始化要找到的層級
1850
				$i=0;
1850
				$i=0;
1851
			
1851
 
1852
				#如果有所屬的層級
1852
				#如果有所屬的層級
1853
				while(isset($def[$keys[$i]])){
1853
				while(isset($def[$keys[$i]])){
1854
				
1854
 
1855
					#取得層級所屬的內容
1855
					#取得層級所屬的內容
1856
					$def=(array)$def[$keys[$i]];
1856
					$def=(array)$def[$keys[$i]];
1857
				
1857
 
1858
					#debug
1858
					#debug
1859
					#var_dump($def);exit;
1859
					#var_dump($def);exit;
1860
				
1860
 
1861
					#如果還不是最後一個key層級
1861
					#如果還不是最後一個key層級
1862
					if(isset($keys[$i+1])){
1862
					if(isset($keys[$i+1])){
1863
					
1863
 
1864
						#層級加一
1864
						#層級加一
1865
						$i++;
1865
						$i++;
1866
					
1866
 
1867
						}#if end
1867
						}#if end
1868
				
1868
 
1869
					#反之是最後一個key的層級了
1869
					#反之是最後一個key的層級了
1870
					else{
1870
					else{
1871
					
1871
 
1872
						#設置定義的內容
1872
						#設置定義的內容
1873
						$result["content"]=$def;
1873
						$result["content"]=$def;
1874
					
1874
 
1875
						#設置有找到定義
1875
						#設置有找到定義
1876
						$result["founded"]="true";
1876
						$result["founded"]="true";
1877
					
1877
 
1878
						#設置定義正常
1878
						#設置定義正常
1879
						$result["status"]="true";
1879
						$result["status"]="true";
1880
					
1880
 
1881
						#回傳結果
1881
						#回傳結果
1882
						return $result;
1882
						return $result;
1883
					
1883
 
1884
						}#else end
1884
						}#else end
1885
				
1885
 
1886
					}#while end
1886
					}#while end
1887
					
1887
 
1888
				#到這邊代表沒有符合的元素
1888
				#到這邊代表沒有符合的元素
1889
			
1889
 
1890
				}#foreach end
1890
				}#foreach end
1891
		
1891
 
1892
			}#if end
1892
			}#if end
1893
	
1893
 
1894
		#反之如果為array
1894
		#反之如果為array
1895
		else if(gettype($conf["configFileAddr"])==="array"){
1895
		else if(gettype($conf["configFileAddr"])==="array"){
1896
		
1896
 
1897
			#針對每行
1897
			#針對每行
1898
			foreach($conf["configFileAddr"] as $configName=>$def){
1898
			foreach($conf["configFileAddr"] as $configName=>$def){
1899
			
1899
 
1900
				#debug
1900
				#debug
1901
				#var_dump($def);exit;
1901
				#var_dump($def);exit;
1902
				#var_dump($keys[$i]);exit;
1902
				#var_dump($keys[$i]);exit;
1903
					
1903
 
1904
				#初始化要找到的層級
1904
				#初始化要找到的層級
1905
				$i=0;
1905
				$i=0;
1906
			
1906
 
1907
				#如果有所屬的層級
1907
				#如果有所屬的層級
1908
				while(isset($def[$keys[$i]])){
1908
				while(isset($def[$keys[$i]])){
1909
				
1909
 
1910
					#取得層級所屬的內容
1910
					#取得層級所屬的內容
1911
					$def=(array)$def[$keys[$i]];
1911
					$def=(array)$def[$keys[$i]];
1912
				
1912
 
1913
					#debug
1913
					#debug
1914
					#var_dump($def);exit;
1914
					#var_dump($def);exit;
1915
				
1915
 
1916
					#如果還不是最後一個key層級
1916
					#如果還不是最後一個key層級
1917
					if(isset($keys[$i+1])){
1917
					if(isset($keys[$i+1])){
1918
					
1918
 
1919
						#層級加一
1919
						#層級加一
1920
						$i++;
1920
						$i++;
1921
					
1921
 
1922
						}#if end
1922
						}#if end
1923
				
1923
 
1924
					#反之是最後一個key的層級了
1924
					#反之是最後一個key的層級了
1925
					else{
1925
					else{
1926
					
1926
 
1927
						#設置定義的內容
1927
						#設置定義的內容
1928
						$result["content"]=$def;
1928
						$result["content"]=$def;
1929
					
1929
 
1930
						#設置有找到定義
1930
						#設置有找到定義
1931
						$result["founded"]="true";
1931
						$result["founded"]="true";
1932
					
1932
 
1933
						#設置定義正常
1933
						#設置定義正常
1934
						$result["status"]="true";
1934
						$result["status"]="true";
1935
					
1935
 
1936
						#回傳結果
1936
						#回傳結果
1937
						return $result;
1937
						return $result;
1938
					
1938
 
1939
						}#else end
1939
						}#else end
1940
				
1940
 
1941
					}#while end
1941
					}#while end
1942
					
1942
 
1943
				#到這邊代表沒有符合的元素
1943
				#到這邊代表沒有符合的元素
1944
			
1944
 
1945
				}#foreach end
1945
				}#foreach end
1946
		
1946
 
1947
			}#if end
1947
			}#if end
1948
			
1948
 
1949
		#反之如果為其他形態
1949
		#反之如果為其他形態
1950
		else{
1950
		else{
1951
		
1951
 
1952
			#設置錯誤識別
1952
			#設置錯誤識別
1953
			$result["status"]="false";
1953
			$result["status"]="false";
1954
			
1954
 
1955
			#設置錯誤訊息
1955
			#設置錯誤訊息
1956
			$result["error"][]="configFileAddr的形態只能為string或array";
1956
			$result["error"][]="configFileAddr的形態只能為string或array";
1957
			
1957
 
1958
			#回傳結果
1958
			#回傳結果
1959
			return $result;
1959
			return $result;
1960
		
1960
 
1961
			}#else end
1961
			}#else end
1962
			
1962
 
1963
		#設置定義正常
1963
		#設置定義正常
1964
		$result["status"]="true";
1964
		$result["status"]="true";
1965
	
1965
 
1966
		#設置沒有找到定義
1966
		#設置沒有找到定義
1967
		$result["founded"]="false";
1967
		$result["founded"]="false";
1968
	
1968
 
1969
		#回傳結果
1969
		#回傳結果
1970
		return $result;
1970
		return $result;
1971
	
1971
 
1972
		}#function server end
1972
		}#function server end
1973
	
1973
 
1974
	/*
1974
	/*
1975
	#函式說明:
1975
	#函式說明:
1976
	#查尋有使用 server 函式提供組態設定檔的服務,取得key的value.
1976
	#查尋有使用 server 函式提供組態設定檔的服務,取得key的value.
1977
	#回傳結果:
1977
	#回傳結果:
1978
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
1978
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
Line 1999... Line 1999...
1999
	#無.
1999
	#無.
2000
	#備註:
2000
	#備註:
2001
	#目前僅能跟server函式提供的服務對接.
2001
	#目前僅能跟server函式提供的服務對接.
2002
	*/
2002
	*/
2003
	public static function client(&$conf=array()){
2003
	public static function client(&$conf=array()){
2004
	
2004
 
2005
		#初始化要回傳的結果
2005
		#初始化要回傳的結果
2006
		$result=array();
2006
		$result=array();
2007
 
2007
 
2008
		#儲存當前執行的函數
2008
		#儲存當前執行的函數
2009
		$result["function"]=__FUNCTION__;
2009
		$result["function"]=__FUNCTION__;
Line 2011... Line 2011...
2011
		#取得參數
2011
		#取得參數
2012
		$result["argu"]=$conf;
2012
		$result["argu"]=$conf;
2013
 
2013
 
2014
		#如果 $conf 不為陣列
2014
		#如果 $conf 不為陣列
2015
		if(gettype($conf)!="array"){
2015
		if(gettype($conf)!="array"){
2016
			
2016
 
2017
			#設置執行失敗
2017
			#設置執行失敗
2018
			$result["status"]="false";
2018
			$result["status"]="false";
2019
			
2019
 
2020
			#設置執行錯誤訊息
2020
			#設置執行錯誤訊息
2021
			$result["error"][]="\$conf變數須為陣列形態";
2021
			$result["error"][]="\$conf變數須為陣列形態";
2022
 
2022
 
2023
			#如果傳入的參數為 null
2023
			#如果傳入的參數為 null
2024
			if($conf==null){
2024
			if($conf==null){
2025
				
2025
 
2026
				#設置執行錯誤訊息
2026
				#設置執行錯誤訊息
2027
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2027
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2028
				
2028
 
2029
				}#if end
2029
				}#if end
2030
 
2030
 
2031
			#回傳結果
2031
			#回傳結果
2032
			return $result;
2032
			return $result;
2033
	
2033
 
2034
			}#if end
2034
			}#if end
2035
	
2035
 
2036
		#檢查參數
2036
		#檢查參數
2037
		#函式說明:
2037
		#函式說明:
2038
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2038
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2039
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2039
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2040
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2040
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 2049... Line 2049...
2049
		#必填寫的參數:
2049
		#必填寫的參數:
2050
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2050
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2051
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2051
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2052
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2052
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2053
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("server","postName","fileArgu");
2053
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("server","postName","fileArgu");
2054
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
2054
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
2055
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
2055
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
2056
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2056
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2057
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2057
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2058
		#可以省略的參數:
2058
		#可以省略的參數:
2059
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2059
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2060
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2060
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2061
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2061
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2062
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("cache","clientCacheDaemonSock","inBg");
2062
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("cache","clientCacheDaemonSock","inBg");
2063
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
2063
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
2064
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
2064
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
2065
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2065
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2066
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true",null,"false");
2066
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true",null,"false");
2067
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2067
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2068
		#$conf["arrayCountEqualCheck"][]=array();
2068
		#$conf["arrayCountEqualCheck"][]=array();
2069
		#參考資料來源:
2069
		#參考資料來源:
2070
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2070
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2071
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2071
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2072
		unset($conf["variableCheck::checkArguments"]);
2072
		unset($conf["variableCheck::checkArguments"]);
2073
	
2073
 
2074
		#如果檢查失敗
2074
		#如果檢查失敗
2075
		if($checkArguments["status"]=="false"){
2075
		if($checkArguments["status"]=="false"){
2076
			
2076
 
2077
			#設置錯誤識別
2077
			#設置錯誤識別
2078
			$result["status"]="false";
2078
			$result["status"]="false";
2079
			
2079
 
2080
			#設置錯誤訊息
2080
			#設置錯誤訊息
2081
			$result["error"]=$checkArguments;
2081
			$result["error"]=$checkArguments;
2082
			
2082
 
2083
			#回傳結果
2083
			#回傳結果
2084
			return $result;
2084
			return $result;
2085
			
2085
 
2086
			}#if end
2086
			}#if end
2087
	
2087
 
2088
		#如果檢查不通過
2088
		#如果檢查不通過
2089
		if($checkArguments["passed"]=="false"){
2089
		if($checkArguments["passed"]=="false"){
2090
			
2090
 
2091
			#設置錯誤識別
2091
			#設置錯誤識別
2092
			$result["status"]="false";
2092
			$result["status"]="false";
2093
			
2093
 
2094
			#設置錯誤訊息
2094
			#設置錯誤訊息
2095
			$result["error"]=$checkArguments;
2095
			$result["error"]=$checkArguments;
2096
			
2096
 
2097
			#回傳結果
2097
			#回傳結果
2098
			return $result;
2098
			return $result;
2099
			
2099
 
2100
			}#if end
2100
			}#if end
2101
		
2101
 
2102
		#如果要在背景執行
2102
		#如果要在背景執行
2103
		if($conf["inBg"]==="true"){
2103
		if($conf["inBg"]==="true"){
2104
		
2104
 
2105
			#函式說明:
2105
			#函式說明:
2106
			#運行curl cmd
2106
			#運行curl cmd
2107
			#回傳結果:
2107
			#回傳結果:
2108
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2108
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2109
			#$result["error"],錯誤訊息陣列.
2109
			#$result["error"],錯誤訊息陣列.
Line 2144... Line 2144...
2144
			#無.
2144
			#無.
2145
			#備註:
2145
			#備註:
2146
			#無.
2146
			#無.
2147
			$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
2147
			$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
2148
			unset($conf["catchWebContent::curlCmd"]);
2148
			unset($conf["catchWebContent::curlCmd"]);
2149
		
2149
 
2150
			#如果執行失敗
2150
			#如果執行失敗
2151
			if($curlCmd["status"]==="false"){
2151
			if($curlCmd["status"]==="false"){
2152
			
2152
 
2153
				#設置錯誤識別
2153
				#設置錯誤識別
2154
				$result["status"]="false";
2154
				$result["status"]="false";
2155
				
2155
 
2156
				#設置錯誤訊息
2156
				#設置錯誤訊息
2157
				$result["error"]=$curlCmd;
2157
				$result["error"]=$curlCmd;
2158
				
2158
 
2159
				#回傳結果
2159
				#回傳結果
2160
				return $result;
2160
				return $result;
2161
			
2161
 
2162
				}#if end
2162
				}#if end
2163
		
2163
 
2164
			#設置proc資訊
2164
			#設置proc資訊
2165
			$result["content"]=$curlCmd["content"];
2165
			$result["content"]=$curlCmd["content"];
2166
		
2166
 
2167
			#設置執行正常
2167
			#設置執行正常
2168
			$result["status"]="true";
2168
			$result["status"]="true";
2169
			
2169
 
2170
			#回傳結果
2170
			#回傳結果
2171
			return $result;
2171
			return $result;
2172
		
2172
 
2173
			}#if end
2173
			}#if end
2174
		
2174
 
2175
		#如果沒有設置 cacheFile
2175
		#如果沒有設置 cacheFile
2176
		if(!isset($conf["cacheFile"])){
2176
		if(!isset($conf["cacheFile"])){
2177
		
2177
 
2178
			#取得以該檔案為准的實際位置 lib path
2178
			#取得以該檔案為准的實際位置 lib path
2179
			exec("cd ".pathinfo(__FILE__)["dirname"].";pwd;",$output,$status);
2179
			exec("cd ".pathinfo(__FILE__)["dirname"].";pwd;",$output,$status);
2180
			
2180
 
2181
			#初始化之
2181
			#初始化之
2182
			$conf["clientCacheDaemonSock"]=$output[0]."/var/config::client/clientCacheDaemon.sock";
2182
			$conf["clientCacheDaemonSock"]=$output[0]."/var/config::client/clientCacheDaemon.sock";
2183
		
2183
 
2184
			}#if end
2184
			}#if end
2185
		
2185
 
2186
		#如果有要使用cache
2186
		#如果有要使用cache
2187
		if($conf["cache"]==="true"){
2187
		if($conf["cache"]==="true"){
2188
		
2188
 
2189
			#查詢 cahce 內容
2189
			#查詢 cahce 內容
2190
			#連線到 sock::unixDomainSocketServer 產生的  unix domain socket,傳送指定的訊息.
2190
			#連線到 sock::unixDomainSocketServer 產生的  unix domain socket,傳送指定的訊息.
2191
			#回傳結果:
2191
			#回傳結果:
2192
			#$result["status"],"true"代表執行正常;"false"代表執行不正常.
2192
			#$result["status"],"true"代表執行正常;"false"代表執行不正常.
2193
			#$result["error"],錯誤訊息陣列.
2193
			#$result["error"],錯誤訊息陣列.
Line 2204... Line 2204...
2204
			#無.
2204
			#無.
2205
			#備註:
2205
			#備註:
2206
			#無.
2206
			#無.
2207
			$sendAnyMsgToQBPWCFunixSocket=sock::sendAnyMsgToQBPWCFunixSocket($conf["sock::sendAnyMsgToQBPWCFunixSocket"]);
2207
			$sendAnyMsgToQBPWCFunixSocket=sock::sendAnyMsgToQBPWCFunixSocket($conf["sock::sendAnyMsgToQBPWCFunixSocket"]);
2208
			unset($conf["sock::sendAnyMsgToQBPWCFunixSocket"]);
2208
			unset($conf["sock::sendAnyMsgToQBPWCFunixSocket"]);
2209
		
2209
 
2210
			#如果執行失敗
2210
			#如果執行失敗
2211
			if($sendAnyMsgToQBPWCFunixSocket["status"]=="false"){
2211
			if($sendAnyMsgToQBPWCFunixSocket["status"]=="false"){
2212
				
2212
 
2213
				#設置錯誤識別
2213
				#設置錯誤識別
2214
				$result["status"]="false";
2214
				$result["status"]="false";
2215
				
2215
 
2216
				#設置錯誤訊息
2216
				#設置錯誤訊息
2217
				$result["error"]=$sendAnyMsgToQBPWCFunixSocket;
2217
				$result["error"]=$sendAnyMsgToQBPWCFunixSocket;
2218
				
2218
 
2219
				#回傳結果
2219
				#回傳結果
2220
				return $result;
2220
				return $result;
2221
				
2221
 
2222
				}#if end
2222
				}#if end
2223
				
2223
 
2224
			#如果執行失敗
2224
			#如果執行失敗
2225
			if($sendAnyMsgToQBPWCFunixSocket["status"]==="false"){
2225
			if($sendAnyMsgToQBPWCFunixSocket["status"]==="false"){
2226
				
2226
 
2227
				#設置錯誤識別
2227
				#設置錯誤識別
2228
				$result["status"]="false";
2228
				$result["status"]="false";
2229
				
2229
 
2230
				#設置錯誤訊息
2230
				#設置錯誤訊息
2231
				$result["error"]=$sendAnyMsgToQBPWCFunixSocket;
2231
				$result["error"]=$sendAnyMsgToQBPWCFunixSocket;
2232
				
2232
 
2233
				#回傳結果
2233
				#回傳結果
2234
				return $result;
2234
				return $result;
2235
				
2235
 
2236
				}#if end
2236
				}#if end
2237
			
2237
 
2238
			#debug
2238
			#debug
2239
			#var_dump(__LINE__,$sendAnyMsgToQBPWCFunixSocket);
2239
			#var_dump(__LINE__,$sendAnyMsgToQBPWCFunixSocket);
2240
			
2240
 
2241
			#設置回應的內容
2241
			#設置回應的內容
2242
			$result["rawContent"]=$sendAnyMsgToQBPWCFunixSocket["content"];
2242
			$result["rawContent"]=$sendAnyMsgToQBPWCFunixSocket["content"];
2243
		
2243
 
2244
			#設置解析好的json回應內容
2244
			#設置解析好的json回應內容
2245
			$result["content"]=json_decode($sendAnyMsgToQBPWCFunixSocket["content"]);
2245
			$result["content"]=json_decode($sendAnyMsgToQBPWCFunixSocket["content"]);
2246
			
2246
 
2247
			#設置執行正常
2247
			#設置執行正常
2248
			$result["status"]="true";
2248
			$result["status"]="true";
2249
			
2249
 
2250
			#回傳結果
2250
			#回傳結果
2251
			return $result;
2251
			return $result;
2252
		
2252
 
2253
			}#if end
2253
			}#if end
2254
		
2254
 
2255
		#函式說明:
2255
		#函式說明:
2256
		#運行curl cmd
2256
		#運行curl cmd
2257
		#回傳結果:
2257
		#回傳結果:
2258
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2258
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2259
		#$result["error"],錯誤訊息陣列.
2259
		#$result["error"],錯誤訊息陣列.
Line 2289... Line 2289...
2289
		#$conf["inBg"]="true";
2289
		#$conf["inBg"]="true";
2290
		#備註:
2290
		#備註:
2291
		#無.
2291
		#無.
2292
		$curlCmd=catchWebContent::curlCmd($conf["cmd::curlCmd"]);
2292
		$curlCmd=catchWebContent::curlCmd($conf["cmd::curlCmd"]);
2293
		unset($conf["cmd::curlCmd"]);
2293
		unset($conf["cmd::curlCmd"]);
2294
	
2294
 
2295
		#如果執行失敗
2295
		#如果執行失敗
2296
		if($curlCmd["status"]==="false"){
2296
		if($curlCmd["status"]==="false"){
2297
		
2297
 
2298
			#設置錯誤識別
2298
			#設置錯誤識別
2299
			$result["status"]="false";
2299
			$result["status"]="false";
2300
			
2300
 
2301
			#設置錯誤訊息
2301
			#設置錯誤訊息
2302
			$result["error"]=$curlCmd;
2302
			$result["error"]=$curlCmd;
2303
			
2303
 
2304
			#回傳結果
2304
			#回傳結果
2305
			return $result;
2305
			return $result;
2306
		
2306
 
2307
			}#if end
2307
			}#if end
2308
		
2308
 
2309
		#設置執行正常
2309
		#設置執行正常
2310
		$result["status"]="true";
2310
		$result["status"]="true";
2311
	
2311
 
2312
		#設置回應的內容
2312
		#設置回應的內容
2313
		$result["rawContent"]=$curlCmd["fullContent"];
2313
		$result["rawContent"]=$curlCmd["fullContent"];
2314
	
2314
 
2315
		#設置解析好的json回應內容
2315
		#設置解析好的json回應內容
2316
		$result["content"]=json_decode($curlCmd["fullContent"]);
2316
		$result["content"]=json_decode($curlCmd["fullContent"]);
2317
		
2317
 
2318
		#回傳結果
2318
		#回傳結果
2319
		return $result;
2319
		return $result;
2320
	
2320
 
2321
		}#function client end
2321
		}#function client end
2322
	
2322
 
2323
	/*
2323
	/*
2324
	#函式說明:
2324
	#函式說明:
2325
	#給clientCacheDaemon用的addOnProcessFunc,處理來自config::client有使用cache的要求.
2325
	#給clientCacheDaemon用的addOnProcessFunc,處理來自config::client有使用cache的要求.
2326
	#回傳結果:
2326
	#回傳結果:
2327
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
2327
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
Line 2357... Line 2357...
2357
	#無.
2357
	#無.
2358
	#備註:
2358
	#備註:
2359
	#無,
2359
	#無,
2360
	*/
2360
	*/
2361
	public static function addOnProcessFuncForClientCacheDaemon(&$conf){
2361
	public static function addOnProcessFuncForClientCacheDaemon(&$conf){
2362
	
2362
 
2363
		#debug
2363
		#debug
2364
		#var_dump(__LINE__,"into function ".__FUNCTION__);
2364
		#var_dump(__LINE__,"into function ".__FUNCTION__);
2365
	
2365
 
2366
		#初始化結果
2366
		#初始化結果
2367
		$result=array();
2367
		$result=array();
2368
 
2368
 
2369
		#取得當前執行的函數名稱
2369
		#取得當前執行的函數名稱
2370
		$result["function"]=__FUNCTION__;
2370
		$result["function"]=__FUNCTION__;
Line 2388... Line 2388...
2388
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2388
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2389
 
2389
 
2390
				}#if end
2390
				}#if end
2391
 
2391
 
2392
			#回傳給用戶 - start
2392
			#回傳給用戶 - start
2393
					
2393
 
2394
			#寫入回應的內容
2394
			#寫入回應的內容
2395
			fwrite($conf["socket"],json_encode($result).PHP_EOL);
2395
			fwrite($conf["socket"],json_encode($result).PHP_EOL);
2396
		
2396
 
2397
			#結束回應
2397
			#結束回應
2398
			fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2398
			fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2399
		
2399
 
2400
			#關閉socket連線,將回應輸出.
2400
			#關閉socket連線,將回應輸出.
2401
			fclose($conf["socket"]);
2401
			fclose($conf["socket"]);
2402
			
2402
 
2403
			#回傳給用戶 - end
2403
			#回傳給用戶 - end
2404
 
2404
 
2405
			#回傳結果
2405
			#回傳結果
2406
			return $result;
2406
			return $result;
2407
 
2407
 
2408
			}#if end
2408
			}#if end
2409
	
2409
 
2410
		#debug
2410
		#debug
2411
		#var_dump(__LINE__,"檢查 參數");
2411
		#var_dump(__LINE__,"檢查 參數");
2412
	
2412
 
2413
		#函式說明:
2413
		#函式說明:
2414
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
2414
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
2415
		#回傳結果:
2415
		#回傳結果:
2416
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2416
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2417
		#$result["error"],執行不正常結束的錯訊息陣列.
2417
		#$result["error"],執行不正常結束的錯訊息陣列.
Line 2462... Line 2462...
2462
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2462
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2463
		#備註:
2463
		#備註:
2464
		#無.
2464
		#無.
2465
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2465
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2466
		unset($conf["variableCheck::checkArguments"]);
2466
		unset($conf["variableCheck::checkArguments"]);
2467
	
2467
 
2468
		#如果執行失敗
2468
		#如果執行失敗
2469
		if($checkArguments["status"]==="false"){
2469
		if($checkArguments["status"]==="false"){
2470
		
2470
 
2471
			#設置錯誤識別
2471
			#設置錯誤識別
2472
			$result["status"]="false";
2472
			$result["status"]="false";
2473
			
2473
 
2474
			#設置錯誤訊息
2474
			#設置錯誤訊息
2475
			$result["error"]=$checkArguments;
2475
			$result["error"]=$checkArguments;
2476
			
2476
 
2477
			#回傳給用戶 - start
2477
			#回傳給用戶 - start
2478
					
2478
 
2479
			#寫入回應的內容
2479
			#寫入回應的內容
2480
			fwrite($conf["socket"],json_encode($result).PHP_EOL);
2480
			fwrite($conf["socket"],json_encode($result).PHP_EOL);
2481
		
2481
 
2482
			#結束回應
2482
			#結束回應
2483
			fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2483
			fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2484
		
2484
 
2485
			#關閉socket連線,將回應輸出.
2485
			#關閉socket連線,將回應輸出.
2486
			fclose($conf["socket"]);
2486
			fclose($conf["socket"]);
2487
			
2487
 
2488
			#回傳給用戶 - end
2488
			#回傳給用戶 - end
2489
			
2489
 
2490
			#回傳結果
2490
			#回傳結果
2491
			return $result;
2491
			return $result;
2492
		
2492
 
2493
			}#if end
2493
			}#if end
2494
			
2494
 
2495
		#如果檢查不通過
2495
		#如果檢查不通過
2496
		if($checkArguments["passed"]==="false"){
2496
		if($checkArguments["passed"]==="false"){
2497
		
2497
 
2498
			#設置錯誤識別
2498
			#設置錯誤識別
2499
			$result["status"]="false";
2499
			$result["status"]="false";
2500
			
2500
 
2501
			#設置錯誤訊息
2501
			#設置錯誤訊息
2502
			$result["error"]=$checkArguments;
2502
			$result["error"]=$checkArguments;
2503
			
2503
 
2504
			#回傳給用戶 - start
2504
			#回傳給用戶 - start
2505
					
2505
 
2506
			#寫入回應的內容
2506
			#寫入回應的內容
2507
			fwrite($conf["socket"],json_encode($result).PHP_EOL);
2507
			fwrite($conf["socket"],json_encode($result).PHP_EOL);
2508
		
2508
 
2509
			#結束回應
2509
			#結束回應
2510
			fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2510
			fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2511
		
2511
 
2512
			#關閉socket連線,將回應輸出.
2512
			#關閉socket連線,將回應輸出.
2513
			fclose($conf["socket"]);
2513
			fclose($conf["socket"]);
2514
			
2514
 
2515
			#回傳給用戶 - end
2515
			#回傳給用戶 - end
2516
			
2516
 
2517
			#回傳結果
2517
			#回傳結果
2518
			return $result;
2518
			return $result;
2519
		
2519
 
2520
			}#if end
2520
			}#if end
2521
	
2521
 
2522
		#debug
2522
		#debug
2523
		#var_dump(__LINE__,"檢查  request 參數");
2523
		#var_dump(__LINE__,"檢查  request 參數");
2524
	
2524
 
2525
		#函式說明:
2525
		#函式說明:
2526
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
2526
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
2527
		#回傳結果:
2527
		#回傳結果:
2528
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2528
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2529
		#$result["error"],執行不正常結束的錯訊息陣列.
2529
		#$result["error"],執行不正常結束的錯訊息陣列.
Line 2574... Line 2574...
2574
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2574
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2575
		#備註:
2575
		#備註:
2576
		#無.
2576
		#無.
2577
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2577
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2578
		unset($conf["variableCheck::checkArguments"]);
2578
		unset($conf["variableCheck::checkArguments"]);
2579
	
2579
 
2580
		#如果執行失敗
2580
		#如果執行失敗
2581
		if($checkArguments["status"]==="false"){
2581
		if($checkArguments["status"]==="false"){
2582
		
2582
 
2583
			#設置錯誤識別
2583
			#設置錯誤識別
2584
			$result["status"]="false";
2584
			$result["status"]="false";
2585
			
2585
 
2586
			#設置錯誤訊息
2586
			#設置錯誤訊息
2587
			$result["error"]=$checkArguments;
2587
			$result["error"]=$checkArguments;
2588
			
2588
 
2589
			#回傳給用戶 - start
2589
			#回傳給用戶 - start
2590
					
2590
 
2591
			#寫入回應的內容
2591
			#寫入回應的內容
2592
			fwrite($conf["socket"],json_encode($result).PHP_EOL);
2592
			fwrite($conf["socket"],json_encode($result).PHP_EOL);
2593
		
2593
 
2594
			#結束回應
2594
			#結束回應
2595
			fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2595
			fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2596
		
2596
 
2597
			#關閉socket連線,將回應輸出.
2597
			#關閉socket連線,將回應輸出.
2598
			fclose($conf["socket"]);
2598
			fclose($conf["socket"]);
2599
			
2599
 
2600
			#回傳給用戶 - end
2600
			#回傳給用戶 - end
2601
			
2601
 
2602
			#回傳結果
2602
			#回傳結果
2603
			return $result;
2603
			return $result;
2604
		
2604
 
2605
			}#if end
2605
			}#if end
2606
			
2606
 
2607
		#如果檢查不通過
2607
		#如果檢查不通過
2608
		if($checkArguments["passed"]==="false"){
2608
		if($checkArguments["passed"]==="false"){
2609
		
2609
 
2610
			#設置錯誤識別
2610
			#設置錯誤識別
2611
			$result["status"]="false";
2611
			$result["status"]="false";
2612
			
2612
 
2613
			#設置錯誤訊息
2613
			#設置錯誤訊息
2614
			$result["error"]=$checkArguments;
2614
			$result["error"]=$checkArguments;
2615
			
2615
 
2616
			#回傳給用戶 - start
2616
			#回傳給用戶 - start
2617
			
2617
 
2618
			#寫入回應的內容
2618
			#寫入回應的內容
2619
			fwrite($conf["socket"],json_encode($result).PHP_EOL);
2619
			fwrite($conf["socket"],json_encode($result).PHP_EOL);
2620
		
2620
 
2621
			#結束回應
2621
			#結束回應
2622
			fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2622
			fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2623
		
2623
 
2624
			#關閉socket連線,將回應輸出.
2624
			#關閉socket連線,將回應輸出.
2625
			fclose($conf["socket"]);
2625
			fclose($conf["socket"]);
2626
			
2626
 
2627
			#回傳給用戶 - end
2627
			#回傳給用戶 - end
2628
			
2628
 
2629
			#回傳結果
2629
			#回傳結果
2630
			return $result;
2630
			return $result;
2631
		
2631
 
2632
			}#if end
2632
			}#if end
2633
			
2633
 
2634
		#函式說明:
2634
		#函式說明:
2635
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
2635
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
2636
		#回傳結果:
2636
		#回傳結果:
2637
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2637
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2638
		#$result["error"],執行不正常結束的錯訊息陣列.
2638
		#$result["error"],執行不正常結束的錯訊息陣列.
Line 2683... Line 2683...
2683
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2683
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2684
		#備註:
2684
		#備註:
2685
		#無.
2685
		#無.
2686
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2686
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2687
		unset($conf["variableCheck::checkArguments"]);
2687
		unset($conf["variableCheck::checkArguments"]);
2688
	
2688
 
2689
		#如果執行失敗
2689
		#如果執行失敗
2690
		if($checkArguments["status"]==="false"){
2690
		if($checkArguments["status"]==="false"){
2691
		
2691
 
2692
			#設置錯誤識別
2692
			#設置錯誤識別
2693
			$result["status"]="false";
2693
			$result["status"]="false";
2694
			
2694
 
2695
			#設置錯誤訊息
2695
			#設置錯誤訊息
2696
			$result["error"]=$checkArguments;
2696
			$result["error"]=$checkArguments;
2697
			
2697
 
2698
			#回傳給用戶 - start
2698
			#回傳給用戶 - start
2699
			
2699
 
2700
			#寫入回應的內容
2700
			#寫入回應的內容
2701
			fwrite($conf["socket"],json_encode($result).PHP_EOL);
2701
			fwrite($conf["socket"],json_encode($result).PHP_EOL);
2702
		
2702
 
2703
			#結束回應
2703
			#結束回應
2704
			fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2704
			fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2705
		
2705
 
2706
			#關閉socket連線,將回應輸出.
2706
			#關閉socket連線,將回應輸出.
2707
			fclose($conf["socket"]);
2707
			fclose($conf["socket"]);
2708
			
2708
 
2709
			#回傳給用戶 - end
2709
			#回傳給用戶 - end
2710
			
2710
 
2711
			#回傳結果
2711
			#回傳結果
2712
			return $result;
2712
			return $result;
2713
		
2713
 
2714
			}#if end
2714
			}#if end
2715
			
2715
 
2716
		#如果檢查不通過
2716
		#如果檢查不通過
2717
		if($checkArguments["passed"]==="false"){
2717
		if($checkArguments["passed"]==="false"){
2718
		
2718
 
2719
			#設置錯誤識別
2719
			#設置錯誤識別
2720
			$result["status"]="false";
2720
			$result["status"]="false";
2721
			
2721
 
2722
			#設置錯誤訊息
2722
			#設置錯誤訊息
2723
			$result["error"]=$checkArguments;
2723
			$result["error"]=$checkArguments;
2724
			
2724
 
2725
			#回傳給用戶 - start
2725
			#回傳給用戶 - start
2726
					
2726
 
2727
			#寫入回應的內容
2727
			#寫入回應的內容
2728
			fwrite($conf["socket"],json_encode($result).PHP_EOL);
2728
			fwrite($conf["socket"],json_encode($result).PHP_EOL);
2729
		
2729
 
2730
			#結束回應
2730
			#結束回應
2731
			fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2731
			fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2732
		
2732
 
2733
			#關閉socket連線,將回應輸出.
2733
			#關閉socket連線,將回應輸出.
2734
			fclose($conf["socket"]);
2734
			fclose($conf["socket"]);
2735
			
2735
 
2736
			#回傳給用戶 - end
2736
			#回傳給用戶 - end
2737
			
2737
 
2738
			#回傳結果
2738
			#回傳結果
2739
			return $result;
2739
			return $result;
2740
		
2740
 
2741
			}#if end
2741
			}#if end
2742
	
2742
 
2743
		#判斷 client cahce 有無指定來源的資料
2743
		#判斷 client cahce 有無指定來源的資料
2744
		
2744
 
2745
		#debug
2745
		#debug
2746
		#var_dump(__LINE__,"判斷 client cahce 有無指定來源的資料");
2746
		#var_dump(__LINE__,"判斷 client cahce 有無指定來源的資料");
2747
		
2747
 
2748
		#來源
2748
		#來源
2749
		#$conf["request"]["server"];
2749
		#$conf["request"]["server"];
2750
		
2750
 
2751
		#debug
2751
		#debug
2752
		#var_dump(__LINE__,$conf["request"]["server"]);
2752
		#var_dump(__LINE__,$conf["request"]["server"]);
2753
		
2753
 
2754
		#索引
2754
		#索引
2755
		#$conf["request"]["postName"];
2755
		#$conf["request"]["postName"];
2756
		
2756
 
2757
		#debug
2757
		#debug
2758
		#var_dump(__LINE__,$conf["request"]["postName"]);
2758
		#var_dump(__LINE__,$conf["request"]["postName"]);
2759
		
2759
 
2760
		#如果存在
2760
		#如果存在
2761
		if(isset($conf["clientCache"]["share"]["configs"])){
2761
		if(isset($conf["clientCache"]["share"]["configs"])){
2762
		
2762
 
2763
			#debug
2763
			#debug
2764
			#var_dump(__LINE__,$conf["clientCache"]["share"]["configs"]);
2764
			#var_dump(__LINE__,$conf["clientCache"]["share"]["configs"]);
2765
		
2765
 
2766
			#如果有對應來源的資料
2766
			#如果有對應來源的資料
2767
			if(isset($conf["clientCache"]["share"]["configs"][$conf["request"]["server"]])){
2767
			if(isset($conf["clientCache"]["share"]["configs"][$conf["request"]["server"]])){
2768
			
2768
 
2769
				#如果有該索引的資料
2769
				#如果有該索引的資料
2770
				if(isset($conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]])){
2770
				if(isset($conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]])){
2771
				
2771
 
2772
					#如果存在 content 跟 time
2772
					#如果存在 content 跟 time
2773
					if( isset($conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]]["content"]) && isset($conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]]["time"]) ){
2773
					if( isset($conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]]["content"]) && isset($conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]]["time"]) ){
2774
					
2774
 
2775
						#取得 content
2775
						#取得 content
2776
						$result["content"]=json_decode($conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]]["content"]);
2776
						$result["content"]=json_decode($conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]]["content"]);
2777
					
2777
 
2778
						#記錄多少秒未更新
2778
						#記錄多少秒未更新
2779
						$secsNoUpdate=time()-$conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]]["time"];
2779
						$secsNoUpdate=time()-$conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]]["time"];
2780
					
2780
 
2781
						#記錄資料過期多少秒
2781
						#記錄資料過期多少秒
2782
						$secsExpired=$secsNoUpdate-$conf["info"]["checkVersionInterval"];
2782
						$secsExpired=$secsNoUpdate-$conf["info"]["checkVersionInterval"];
2783
					
2783
 
2784
						#提示資料超過期限未更新
2784
						#提示資料超過期限未更新
2785
						if($secsNoUpdate>$conf["info"]["checkVersionInterval"]){
2785
						if($secsNoUpdate>$conf["info"]["checkVersionInterval"]){
2786
						
2786
 
2787
							#設置警告訊息
2787
							#設置警告訊息
2788
							$result["warning"][]="data expired for ".$secsExpired." secs";
2788
							$result["warning"][]="data expired for ".$secsExpired." secs";
2789
						
2789
 
2790
							}#if end 
2790
							}#if end
2791
							
2791
 
2792
						#設置執行正常
2792
						#設置執行正常
2793
						$result["status"]="true";
2793
						$result["status"]="true";
2794
			
2794
 
2795
						#debug
2795
						#debug
2796
						#var_dump(__LINE__,$result,json_encode($result));
2796
						#var_dump(__LINE__,$result,json_encode($result));
2797
			
2797
 
2798
						#回傳給用戶 - start
2798
						#回傳給用戶 - start
2799
						
2799
 
2800
						#初始化要回傳的訊息
2800
						#初始化要回傳的訊息
2801
						$msg=array();
2801
						$msg=array();
2802
						
2802
 
2803
						#設置回傳的內容
2803
						#設置回傳的內容
2804
						$msg["content"]=$result["content"];
2804
						$msg["content"]=$result["content"];
2805
						
2805
 
2806
						#設置回傳的狀態
2806
						#設置回傳的狀態
2807
						$msg["status"]=$result["status"];
2807
						$msg["status"]=$result["status"];
2808
						
2808
 
2809
						#寫入回應的內容
2809
						#寫入回應的內容
2810
						fwrite($conf["socket"],json_encode($msg).PHP_EOL);
2810
						fwrite($conf["socket"],json_encode($msg).PHP_EOL);
2811
					
2811
 
2812
						#結束回應
2812
						#結束回應
2813
						fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2813
						fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2814
					
2814
 
2815
						#關閉socket連線,將回應輸出.
2815
						#關閉socket連線,將回應輸出.
2816
						fclose($conf["socket"]);
2816
						fclose($conf["socket"]);
2817
						
2817
 
2818
						#回傳給用戶 - end
2818
						#回傳給用戶 - end
2819
			
2819
 
2820
						#回傳結果
2820
						#回傳結果
2821
						return $result;
2821
						return $result;
2822
			
2822
 
2823
						}#if end
2823
						}#if end
2824
				
2824
 
2825
					}#if end
2825
					}#if end
2826
			
2826
 
2827
				}#if end
2827
				}#if end
2828
		
2828
 
2829
			}#if end
2829
			}#if end
2830
			
2830
 
2831
		#執行到這邊代表沒有資料
2831
		#執行到這邊代表沒有資料
2832
		
2832
 
2833
		#函式說明:
2833
		#函式說明:
2834
		#查尋有使用 server 函式提供組態設定檔的服務,取得key的value.
2834
		#查尋有使用 server 函式提供組態設定檔的服務,取得key的value.
2835
		#回傳結果:
2835
		#回傳結果:
2836
		#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
2836
		#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
2837
		#$result["error"],錯誤訊息陣列.
2837
		#$result["error"],錯誤訊息陣列.
Line 2854... Line 2854...
2854
		#無.
2854
		#無.
2855
		#備註:
2855
		#備註:
2856
		#目前僅能跟server函式提供的服務對接.
2856
		#目前僅能跟server函式提供的服務對接.
2857
		$client=config::client($conf["config::client"]);
2857
		$client=config::client($conf["config::client"]);
2858
		unset($conf["config::client"]);
2858
		unset($conf["config::client"]);
2859
	
2859
 
2860
		#debug
2860
		#debug
2861
		#var_dump(__LINE__,$client);
2861
		#var_dump(__LINE__,$client);
2862
	
2862
 
2863
		/*
2863
		/*
2864
	
2864
 
2865
		#debug
2865
		#debug
2866
		#函式說明:
2866
		#函式說明:
2867
		#撰寫log
2867
		#撰寫log
2868
		#回傳結果:
2868
		#回傳結果:
2869
		#$result["status"],狀態,"true"或"false".
2869
		#$result["status"],狀態,"true"或"false".
Line 2887... Line 2887...
2887
		#無.
2887
		#無.
2888
		#備註:
2888
		#備註:
2889
		#無.
2889
		#無.
2890
		config::record($conf["config::record"]);
2890
		config::record($conf["config::record"]);
2891
		unset($conf["config::record"]);
2891
		unset($conf["config::record"]);
2892
		
2892
 
2893
		*/
2893
		*/
2894
	
2894
 
2895
		#如果執行失敗
2895
		#如果執行失敗
2896
		if($client["status"]==="false"){
2896
		if($client["status"]==="false"){
2897
		
2897
 
2898
			#設置錯誤識別
2898
			#設置錯誤識別
2899
			$result["status"]="false";
2899
			$result["status"]="false";
2900
			
2900
 
2901
			#設置錯誤訊息
2901
			#設置錯誤訊息
2902
			$result["error"]=$client;
2902
			$result["error"]=$client;
2903
			
2903
 
2904
			#回傳給用戶 - start
2904
			#回傳給用戶 - start
2905
					
2905
 
2906
			#寫入回應的內容
2906
			#寫入回應的內容
2907
			fwrite($conf["socket"],json_encode($result).PHP_EOL);
2907
			fwrite($conf["socket"],json_encode($result).PHP_EOL);
2908
		
2908
 
2909
			#結束回應
2909
			#結束回應
2910
			fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2910
			fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2911
		
2911
 
2912
			#關閉socket連線,將回應輸出.
2912
			#關閉socket連線,將回應輸出.
2913
			fclose($conf["socket"]);
2913
			fclose($conf["socket"]);
2914
			
2914
 
2915
			#回傳給用戶 - end
2915
			#回傳給用戶 - end
2916
			
2916
 
2917
			#回傳結果
2917
			#回傳結果
2918
			return $result;
2918
			return $result;
2919
		
2919
 
2920
			}#if end
2920
			}#if end
2921
 
2921
 
2922
		#新增 client cache 內容
2922
		#新增 client cache 內容
2923
		$conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]]["content"]=$client["rawContent"];
2923
		$conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]]["content"]=$client["rawContent"];
2924
 
2924
 
Line 2931... Line 2931...
2931
		#初始化要傳遞的訊息
2931
		#初始化要傳遞的訊息
2932
		$msg=array();
2932
		$msg=array();
2933
 
2933
 
2934
		#設置 msg content
2934
		#設置 msg content
2935
		$msg["content"]=$client["rawContent"];
2935
		$msg["content"]=$client["rawContent"];
2936
		
2936
 
2937
		#設置 msg status
2937
		#設置 msg status
2938
		$msg["status"]="true";
2938
		$msg["status"]="true";
2939
		
2939
 
2940
		#設置執行正常
2940
		#設置執行正常
2941
		$result["status"]="true";
2941
		$result["status"]="true";
2942
 
2942
 
2943
		#回傳給用戶 - start
2943
		#回傳給用戶 - start
2944
		
2944
 
2945
		#寫入回應的內容
2945
		#寫入回應的內容
2946
		fwrite($conf["socket"],json_encode($msg).PHP_EOL);
2946
		fwrite($conf["socket"],json_encode($msg).PHP_EOL);
2947
	
2947
 
2948
		#結束回應
2948
		#結束回應
2949
		fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2949
		fwrite($conf["socket"],PHP_EOL.PHP_EOL);
2950
	
2950
 
2951
		#關閉socket連線,將回應輸出.
2951
		#關閉socket連線,將回應輸出.
2952
		fclose($conf["socket"]);
2952
		fclose($conf["socket"]);
2953
		
2953
 
2954
		#回傳給用戶 - end
2954
		#回傳給用戶 - end
2955
 
2955
 
2956
		#回傳結果
2956
		#回傳結果
2957
		return $result;
2957
		return $result;
2958
	
2958
 
2959
		}#function addOnProcessFuncForClientCacheDaemon end
2959
		}#function addOnProcessFuncForClientCacheDaemon end
2960
	
2960
 
2961
	/*
2961
	/*
2962
	#函式說明:
2962
	#函式說明:
2963
	#給clientCacheDaemon用的funcToRunWhenIdle,處理來自config::client產生的cache內容,若過期就更新,若跟cache檔案不同就更新檔案,若有cache檔案但尚未cache住就cache之.
2963
	#給clientCacheDaemon用的funcToRunWhenIdle,處理來自config::client產生的cache內容,若過期就更新,若跟cache檔案不同就更新檔案,若有cache檔案但尚未cache住就cache之.
2964
	#回傳結果:
2964
	#回傳結果:
2965
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
2965
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
Line 2985... Line 2985...
2985
	#無.
2985
	#無.
2986
	#備註:
2986
	#備註:
2987
	#無,
2987
	#無,
2988
	*/
2988
	*/
2989
	public static function funcToRunWhenIdleForClientCacheDaemon(&$conf){
2989
	public static function funcToRunWhenIdleForClientCacheDaemon(&$conf){
2990
	
2990
 
2991
		$result=array();
2991
		$result=array();
2992
 
2992
 
2993
		#取得當前執行的函數名稱
2993
		#取得當前執行的函數名稱
2994
		$result["function"]=__FUNCTION__;
2994
		$result["function"]=__FUNCTION__;
2995
 
2995
 
Line 3015... Line 3015...
3015
 
3015
 
3016
			#回傳結果
3016
			#回傳結果
3017
			return $result;
3017
			return $result;
3018
 
3018
 
3019
			}#if end
3019
			}#if end
3020
	
3020
 
3021
		#函式說明:
3021
		#函式說明:
3022
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
3022
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
3023
		#回傳結果:
3023
		#回傳結果:
3024
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3024
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3025
		#$result["error"],執行不正常結束的錯訊息陣列.
3025
		#$result["error"],執行不正常結束的錯訊息陣列.
Line 3070... Line 3070...
3070
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3070
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3071
		#備註:
3071
		#備註:
3072
		#無.
3072
		#無.
3073
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3073
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3074
		unset($conf["variableCheck::checkArguments"]);
3074
		unset($conf["variableCheck::checkArguments"]);
3075
	
3075
 
3076
		#如果執行失敗
3076
		#如果執行失敗
3077
		if($checkArguments["status"]==="false"){
3077
		if($checkArguments["status"]==="false"){
3078
		
3078
 
3079
			#設置錯誤識別
3079
			#設置錯誤識別
3080
			$result["status"]="false";
3080
			$result["status"]="false";
3081
			
3081
 
3082
			#設置錯誤訊息
3082
			#設置錯誤訊息
3083
			$result["error"]=$checkArguments;
3083
			$result["error"]=$checkArguments;
3084
			
3084
 
3085
			#回傳結果
3085
			#回傳結果
3086
			return $result;
3086
			return $result;
3087
		
3087
 
3088
			}#if end
3088
			}#if end
3089
			
3089
 
3090
		#如果檢查不通過
3090
		#如果檢查不通過
3091
		if($checkArguments["passed"]==="false"){
3091
		if($checkArguments["passed"]==="false"){
3092
		
3092
 
3093
			#設置錯誤識別
3093
			#設置錯誤識別
3094
			$result["status"]="false";
3094
			$result["status"]="false";
3095
			
3095
 
3096
			#設置錯誤訊息
3096
			#設置錯誤訊息
3097
			$result["error"]=$checkArguments;
3097
			$result["error"]=$checkArguments;
3098
			
3098
 
3099
			#回傳結果
3099
			#回傳結果
3100
			return $result;
3100
			return $result;
3101
		
3101
 
3102
			}#if end
3102
			}#if end
3103
	
3103
 
3104
		#debug
3104
		#debug
3105
		#var_dump(__LINE__,$conf);
3105
		#var_dump(__LINE__,$conf);
3106
	
3106
 
3107
		#函式說明:
3107
		#函式說明:
3108
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
3108
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
3109
		#回傳結果:
3109
		#回傳結果:
3110
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3110
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3111
		#$result["error"],執行不正常結束的錯訊息陣列.
3111
		#$result["error"],執行不正常結束的錯訊息陣列.
Line 3156... Line 3156...
3156
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3156
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3157
		#備註:
3157
		#備註:
3158
		#無.
3158
		#無.
3159
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3159
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3160
		unset($conf["variableCheck::checkArguments"]);
3160
		unset($conf["variableCheck::checkArguments"]);
3161
	
3161
 
3162
		#如果執行失敗
3162
		#如果執行失敗
3163
		if($checkArguments["status"]==="false"){
3163
		if($checkArguments["status"]==="false"){
3164
		
3164
 
3165
			#設置錯誤識別
3165
			#設置錯誤識別
3166
			$result["status"]="false";
3166
			$result["status"]="false";
3167
			
3167
 
3168
			#設置錯誤訊息
3168
			#設置錯誤訊息
3169
			$result["error"]=$checkArguments;
3169
			$result["error"]=$checkArguments;
3170
			
3170
 
3171
			#回傳結果
3171
			#回傳結果
3172
			return $result;
3172
			return $result;
3173
		
3173
 
3174
			}#if end
3174
			}#if end
3175
			
3175
 
3176
		#如果檢查不通過
3176
		#如果檢查不通過
3177
		if($checkArguments["passed"]==="false"){
3177
		if($checkArguments["passed"]==="false"){
3178
		
3178
 
3179
			#設置錯誤識別
3179
			#設置錯誤識別
3180
			$result["status"]="false";
3180
			$result["status"]="false";
3181
			
3181
 
3182
			#設置錯誤訊息
3182
			#設置錯誤訊息
3183
			$result["error"]=$checkArguments;
3183
			$result["error"]=$checkArguments;
3184
			
3184
 
3185
			#回傳結果
3185
			#回傳結果
3186
			return $result;
3186
			return $result;
3187
		
3187
 
3188
			}#if end
3188
			}#if end
3189
	
3189
 
3190
		#另存 cacheFilePath
3190
		#另存 cacheFilePath
3191
		$cacheFilePath=$conf["info"]["cacheFilePath"];
3191
		$cacheFilePath=$conf["info"]["cacheFilePath"];
3192
	
3192
 
3193
		#另存 checkVersionInterval
3193
		#另存 checkVersionInterval
3194
		$checkVersionInterval=$conf["info"]["checkVersionInterval"];
3194
		$checkVersionInterval=$conf["info"]["checkVersionInterval"];
3195
	
3195
 
3196
		#檢查之前執行的 config:client - start
3196
		#檢查之前執行的 config:client - start
3197
	
3197
 
3198
		#如果有儲存之前執行的 config:client
3198
		#如果有儲存之前執行的 config:client
3199
		if(isset($conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"])){
3199
		if(isset($conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"])){
3200
		
3200
 
3201
			#針對每個 proc 
3201
			#針對每個 proc
3202
			foreach($conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"] as $index => $porc){
3202
			foreach($conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"] as $index => $porc){
3203
			
3203
 
3204
				#如果程序已經結束
3204
				#如果程序已經結束
3205
				if($porc["proc_get_status"]["running"]===false){
3205
				if($porc["proc_get_status"]["running"]===false){
3206
				
3206
 
3207
					#如果程序正常結束
3207
					#如果程序正常結束
3208
					if($porc["proc_get_status"]["exitcode"]===0){
3208
					if($porc["proc_get_status"]["exitcode"]===0){
3209
					
3209
 
3210
						#取得輸出
3210
						#取得輸出
3211
						$clientConfigRes=stream_get_contents($porc["content"]);
3211
						$clientConfigRes=stream_get_contents($porc["content"]);
3212
					
3212
 
3213
						#set json string content
3213
						#set json string content
3214
						$conf["serverCache"]["clientSide"]["share"]["configs"][$porc["server"]][$proc["postName"]]["content"]=$clientConfigRes;
3214
						$conf["serverCache"]["clientSide"]["share"]["configs"][$porc["server"]][$proc["postName"]]["content"]=$clientConfigRes;
3215
											
3215
 
3216
						}#if end
3216
						}#if end
3217
				
3217
 
3218
					#移除之
3218
					#移除之
3219
					unset($conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"][$index]);
3219
					unset($conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"][$index]);
3220
				
3220
 
3221
					}#if end
3221
					}#if end
3222
				 
3222
 
3223
				#反之
3223
				#反之
3224
				else {
3224
				else {
3225
				
3225
 
3226
					#更新 proc_get_status
3226
					#更新 proc_get_status
3227
					$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"][$index]["proc_get_status"]=proc_get_status($porc["process"]);
3227
					$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"][$index]["proc_get_status"]=proc_get_status($porc["process"]);
3228
				
3228
 
3229
					}#else end
3229
					}#else end
3230
			
3230
 
3231
				}#foreach end
3231
				}#foreach end
3232
		
3232
 
3233
			#儲存 procs 的元素數量
3233
			#儲存 procs 的元素數量
3234
			$procsCount=count($conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"]);
3234
			$procsCount=count($conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"]);
3235
		
3235
 
3236
			#如果有proc尚未結束
3236
			#如果有proc尚未結束
3237
			if($procsCount>0){
3237
			if($procsCount>0){
3238
			
3238
 
3239
				#提示之
3239
				#提示之
3240
				echo "尚有 ".$procsCount." 個取得 config 的程序執行中".PHP_EOL;
3240
				echo "尚有 ".$procsCount." 個取得 config 的程序執行中".PHP_EOL;
3241
				
3241
 
3242
				#設置執行正常
3242
				#設置執行正常
3243
				$result["status"]="true";
3243
				$result["status"]="true";
3244
				
3244
 
3245
				#回傳結果
3245
				#回傳結果
3246
				return $result;
3246
				return $result;
3247
			
3247
 
3248
				}#if end
3248
				}#if end
3249
			
3249
 
3250
			}#if end
3250
			}#if end
3251
	
3251
 
3252
		#檢查之前執行的 config:client - end
3252
		#檢查之前執行的 config:client - end
3253
	
3253
 
3254
		#檢查有每個 cache 檔案,若沒有對應的 clientCache,則 cache 之. - start
3254
		#檢查有每個 cache 檔案,若沒有對應的 clientCache,則 cache 之. - start
3255
		
3255
 
3256
		#函式說明:
3256
		#函式說明:
3257
		#取得目錄底下的詳細資訊.
3257
		#取得目錄底下的詳細資訊.
3258
		#回傳結果:
3258
		#回傳結果:
3259
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3259
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3260
		#$result["error"],錯誤訊息.
3260
		#$result["error"],錯誤訊息.
Line 3282... Line 3282...
3282
		#https://www.businessweekly.com.tw/careers/Blog/14307
3282
		#https://www.businessweekly.com.tw/careers/Blog/14307
3283
		#備註:
3283
		#備註:
3284
		#清單要不包含 "."開頭 跟 "~" 開頭
3284
		#清單要不包含 "."開頭 跟 "~" 開頭
3285
		$ls=fileAccess::ls($conf["fileAccess::ls"]);
3285
		$ls=fileAccess::ls($conf["fileAccess::ls"]);
3286
		unset($conf["fileAccess::ls"]);
3286
		unset($conf["fileAccess::ls"]);
3287
		
3287
 
3288
		#如果執行失敗
3288
		#如果執行失敗
3289
		if($ls["status"]==="false"){
3289
		if($ls["status"]==="false"){
3290
		
3290
 
3291
			#設置錯誤識別
3291
			#設置錯誤識別
3292
			$result["status"]="false";
3292
			$result["status"]="false";
3293
			
3293
 
3294
			#設置錯誤訊息
3294
			#設置錯誤訊息
3295
			$result["error"]=$ls;
3295
			$result["error"]=$ls;
3296
			
3296
 
3297
			#debug
3297
			#debug
3298
			var_dump(__LINE__,$result);
3298
			var_dump(__LINE__,$result);
3299
			
3299
 
3300
			#回傳結果
3300
			#回傳結果
3301
			return $result;
3301
			return $result;
3302
		
3302
 
3303
			}#if end
3303
			}#if end
3304
		
3304
 
3305
		#針對每個節點
3305
		#針對每個節點
3306
		foreach($ls["content"] as $nodeInfo){
3306
		foreach($ls["content"] as $nodeInfo){
3307
		
3307
 
3308
			#檔案名稱
3308
			#檔案名稱
3309
			#$nodeInfo["name"]
3309
			#$nodeInfo["name"]
3310
		
3310
 
3311
			#已經chche後的檔案陣列
3311
			#已經chche後的檔案陣列
3312
			#$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["cachedFile"]
3312
			#$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["cachedFile"]
3313
		
3313
 
3314
			#如果沒有已經cache的項目
3314
			#如果沒有已經cache的項目
3315
			if(!isset($conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"])){
3315
			if(!isset($conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"])){
3316
			
3316
 
3317
				#初始化之
3317
				#初始化之
3318
				$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["cachedFile"]=array();
3318
				$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["cachedFile"]=array();
3319
			
3319
 
3320
				}#if end
3320
				}#if end
3321
		
3321
 
3322
			#函式說明:
3322
			#函式說明:
3323
			#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
3323
			#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
3324
			#回傳結果:
3324
			#回傳結果:
3325
			#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
3325
			#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
3326
			#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
3326
			#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
Line 3340... Line 3340...
3340
			#無.
3340
			#無.
3341
			#備註:
3341
			#備註:
3342
			#無.
3342
			#無.
3343
			$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
3343
			$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
3344
			unset($conf["search::getEqualVar"]);
3344
			unset($conf["search::getEqualVar"]);
3345
			
3345
 
3346
			#debug
3346
			#debug
3347
			#var_dump(__LINE__,$getEqualVar);
3347
			#var_dump(__LINE__,$getEqualVar);
3348
			
3348
 
3349
			#如果執行失敗
3349
			#如果執行失敗
3350
			if($getEqualVar["status"]==="false"){
3350
			if($getEqualVar["status"]==="false"){
3351
			
3351
 
3352
				#設置錯誤識別
3352
				#設置錯誤識別
3353
				$result["status"]="false";
3353
				$result["status"]="false";
3354
				
3354
 
3355
				#設置錯誤訊息
3355
				#設置錯誤訊息
3356
				$result["error"]=$getEqualVar;
3356
				$result["error"]=$getEqualVar;
3357
				
3357
 
3358
				#debug
3358
				#debug
3359
				var_dump(__LINE__,$result);
3359
				var_dump(__LINE__,$result);
3360
				
3360
 
3361
				#回傳結果
3361
				#回傳結果
3362
				return $result;
3362
				return $result;
3363
			
3363
 
3364
				}#if end
3364
				}#if end
3365
			
3365
 
3366
			#如果已經cache過
3366
			#如果已經cache過
3367
			if($getEqualVar["founded"]==="true"){
3367
			if($getEqualVar["founded"]==="true"){
3368
			
3368
 
3369
				#換下個檔案
3369
				#換下個檔案
3370
				continue;
3370
				continue;
3371
			
3371
 
3372
				}#if end
3372
				}#if end
3373
			
3373
 
3374
			#debug
3374
			#debug
3375
			#var_dump(__LINE__,$getEqualVar);
3375
			#var_dump(__LINE__,$getEqualVar);
3376
			
3376
 
3377
			#如果是檔案
3377
			#如果是檔案
3378
			if($nodeInfo["nType"]==="-"){
3378
			if($nodeInfo["nType"]==="-"){
3379
			
3379
 
3380
				#debug
3380
				#debug
3381
				#var_dump(__LINE__,"檢測尚未cache的檔案",$nodeInfo);
3381
				#var_dump(__LINE__,"檢測尚未cache的檔案",$nodeInfo);
3382
						
3382
 
3383
				#判斷是否為cache檔案,範例:"client::config-cache-".urlencode($conf["request"]["postName"])." from ".urlencode($conf["request"]["server"]).".json";
3383
				#判斷是否為cache檔案,範例:"client::config-cache-".urlencode($conf["request"]["postName"])." from ".urlencode($conf["request"]["server"]).".json";
3384
				#函式說明:
3384
				#函式說明:
3385
				#檢查字串是否符合指定格式
3385
				#檢查字串是否符合指定格式
3386
				#回傳結果:
3386
				#回傳結果:
3387
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3387
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 3414... Line 3414...
3414
				#grapheme_substr=>https://www.php.net/manual/en/function.grapheme-substr.php
3414
				#grapheme_substr=>https://www.php.net/manual/en/function.grapheme-substr.php
3415
				#備註:
3415
				#備註:
3416
				#無.
3416
				#無.
3417
				$checkStringFormat=variableCheck::checkStringFormat($conf["variableCheck::checkStringFormat"]);
3417
				$checkStringFormat=variableCheck::checkStringFormat($conf["variableCheck::checkStringFormat"]);
3418
				unset($conf["variableCheck::checkStringFormat"]);
3418
				unset($conf["variableCheck::checkStringFormat"]);
3419
			
3419
 
3420
				#debug
3420
				#debug
3421
				#var_dump(__LINE__,$checkStringFormat);
3421
				#var_dump(__LINE__,$checkStringFormat);
3422
			
3422
 
3423
				#如果執行失敗
3423
				#如果執行失敗
3424
				if($checkStringFormat["status"]==="false"){
3424
				if($checkStringFormat["status"]==="false"){
3425
				
3425
 
3426
					#設置錯誤識別
3426
					#設置錯誤識別
3427
					$result["status"]="false";
3427
					$result["status"]="false";
3428
					
3428
 
3429
					#設置錯誤訊息
3429
					#設置錯誤訊息
3430
					$result["error"]=$checkStringFormat;
3430
					$result["error"]=$checkStringFormat;
3431
					
3431
 
3432
					#debug
3432
					#debug
3433
					var_dump(__LINE__,$result);
3433
					var_dump(__LINE__,$result);
3434
					
3434
 
3435
					#回傳結果
3435
					#回傳結果
3436
					return $result;
3436
					return $result;
3437
				
3437
 
3438
					}#if end
3438
					}#if end
3439
					
3439
 
3440
				#如果是符合的暫存檔案
3440
				#如果是符合的暫存檔案
3441
				if($checkStringFormat["passed"]==="true"){
3441
				if($checkStringFormat["passed"]==="true"){
3442
				
3442
 
3443
					#解析對應的 postName 與 server - start
3443
					#解析對應的 postName 與 server - start
3444
					
3444
 
3445
					#函式說明:
3445
					#函式說明:
3446
					#將字串特定關鍵字與其前面的內容剔除
3446
					#將字串特定關鍵字與其前面的內容剔除
3447
					#回傳結果:
3447
					#回傳結果:
3448
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3448
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3449
					#$result["error"],錯誤訊息陣列.
3449
					#$result["error"],錯誤訊息陣列.
3450
					#$result["warning"],警告訊息鎮列.
3450
					#$result["warning"],警告訊息鎮列.
3451
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
3451
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
3452
					#$result["function"],當前執行的函數名稱.
3452
					#$result["function"],當前執行的函數名稱.
3453
					#$result["argu"],使用的參數.
3453
					#$result["argu"],使用的參數.
3454
					#$result["oriStr"],要處理的原始字串內容.
3454
					#$result["oriStr"],要處理的原始字串內容.
3455
					#$result["content"],處理好的的字串內容.	
3455
					#$result["content"],處理好的的字串內容.
3456
					#必填參數:
3456
					#必填參數:
3457
					#$conf["stringIn"],字串,要處理的字串.
3457
					#$conf["stringIn"],字串,要處理的字串.
3458
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$nodeInfo["name"];
3458
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$nodeInfo["name"];
3459
					#$conf["keyWord"],字串,特定字串.
3459
					#$conf["keyWord"],字串,特定字串.
3460
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="client::config-cache-";
3460
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="client::config-cache-";
Line 3467... Line 3467...
3467
					#無.
3467
					#無.
3468
					#備註:
3468
					#備註:
3469
					#無.
3469
					#無.
3470
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
3470
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
3471
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
3471
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
3472
					
3472
 
3473
					#如果執行失敗
3473
					#如果執行失敗
3474
					if($delStrBeforeKeyWord["status"]==="false"){
3474
					if($delStrBeforeKeyWord["status"]==="false"){
3475
					
3475
 
3476
						#設置錯誤識別
3476
						#設置錯誤識別
3477
						$result["status"]="false";
3477
						$result["status"]="false";
3478
						
3478
 
3479
						#設置錯誤訊息
3479
						#設置錯誤訊息
3480
						$result["error"]=$delStrBeforeKeyWord;
3480
						$result["error"]=$delStrBeforeKeyWord;
3481
						
3481
 
3482
						#debug
3482
						#debug
3483
						var_dump(__LINE__,$result);
3483
						var_dump(__LINE__,$result);
3484
						
3484
 
3485
						#回傳結果
3485
						#回傳結果
3486
						return $result;
3486
						return $result;
3487
					
3487
 
3488
						}#if end
3488
						}#if end
3489
					
3489
 
3490
					#如果沒有關鍵字
3490
					#如果沒有關鍵字
3491
					if($delStrBeforeKeyWord["founded"]==="false"){
3491
					if($delStrBeforeKeyWord["founded"]==="false"){
3492
					
3492
 
3493
						#設置錯誤識別
3493
						#設置錯誤識別
3494
						$result["status"]="false";
3494
						$result["status"]="false";
3495
						
3495
 
3496
						#設置錯誤訊息
3496
						#設置錯誤訊息
3497
						$result["error"]=$delStrBeforeKeyWord;
3497
						$result["error"]=$delStrBeforeKeyWord;
3498
						
3498
 
3499
						#debug
3499
						#debug
3500
						var_dump(__LINE__,$result);
3500
						var_dump(__LINE__,$result);
3501
						
3501
 
3502
						#回傳結果
3502
						#回傳結果
3503
						return $result;
3503
						return $result;
3504
					
3504
 
3505
						}#if end
3505
						}#if end
3506
					
3506
 
3507
					#函式說明:
3507
					#函式說明:
3508
					#將字串特定關鍵字與其後面的內容剔除
3508
					#將字串特定關鍵字與其後面的內容剔除
3509
					#回傳結果:
3509
					#回傳結果:
3510
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3510
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3511
					#$result["error"],錯誤訊息陣列.
3511
					#$result["error"],錯誤訊息陣列.
Line 3527... Line 3527...
3527
					#無.
3527
					#無.
3528
					#備註:
3528
					#備註:
3529
					#無.
3529
					#無.
3530
					$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
3530
					$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
3531
					unset($conf["stringProcess::delStrAfterKeyWord"]);
3531
					unset($conf["stringProcess::delStrAfterKeyWord"]);
3532
					
3532
 
3533
					#如果執行失敗
3533
					#如果執行失敗
3534
					if($delStrAfterKeyWord["status"]==="false"){
3534
					if($delStrAfterKeyWord["status"]==="false"){
3535
					
3535
 
3536
						#設置錯誤識別
3536
						#設置錯誤識別
3537
						$result["status"]="false";
3537
						$result["status"]="false";
3538
						
3538
 
3539
						#設置錯誤訊息
3539
						#設置錯誤訊息
3540
						$result["error"]=$delStrAfterKeyWord;
3540
						$result["error"]=$delStrAfterKeyWord;
3541
						
3541
 
3542
						#debug
3542
						#debug
3543
						var_dump(__LINE__,$result);
3543
						var_dump(__LINE__,$result);
3544
						
3544
 
3545
						#回傳結果
3545
						#回傳結果
3546
						return $result;
3546
						return $result;
3547
					
3547
 
3548
						}#if end
3548
						}#if end
3549
						
3549
 
3550
					#如果沒有關鍵字
3550
					#如果沒有關鍵字
3551
					if($delStrAfterKeyWord["founded"]==="false"){
3551
					if($delStrAfterKeyWord["founded"]==="false"){
3552
					
3552
 
3553
						#設置錯誤識別
3553
						#設置錯誤識別
3554
						$result["status"]="false";
3554
						$result["status"]="false";
3555
						
3555
 
3556
						#設置錯誤訊息
3556
						#設置錯誤訊息
3557
						$result["error"]=$delStrAfterKeyWord;
3557
						$result["error"]=$delStrAfterKeyWord;
3558
						
3558
 
3559
						#debug
3559
						#debug
3560
						var_dump(__LINE__,$result);
3560
						var_dump(__LINE__,$result);
3561
						
3561
 
3562
						#回傳結果
3562
						#回傳結果
3563
						return $result;
3563
						return $result;
3564
					
3564
 
3565
						}#if end
3565
						}#if end
3566
					
3566
 
3567
					#另存postName與server的字串
3567
					#另存postName與server的字串
3568
					$postNameAndServerStr=$delStrAfterKeyWord["content"];
3568
					$postNameAndServerStr=$delStrAfterKeyWord["content"];
3569
					
3569
 
3570
					#用 " from " 來切割
3570
					#用 " from " 來切割
3571
					#函式說明:
3571
					#函式說明:
3572
					#將固定格式的字串分開,並回傳分開的結果.
3572
					#將固定格式的字串分開,並回傳分開的結果.
3573
					#回傳結果:
3573
					#回傳結果:
3574
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3574
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 3591... Line 3591...
3591
					#無.
3591
					#無.
3592
					#備註:
3592
					#備註:
3593
					#無.
3593
					#無.
3594
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
3594
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
3595
					unset($conf["stringProcess::spiltString"]);
3595
					unset($conf["stringProcess::spiltString"]);
3596
					
3596
 
3597
					#如果執行失敗
3597
					#如果執行失敗
3598
					if($spiltString["status"]==="false"){
3598
					if($spiltString["status"]==="false"){
3599
					
3599
 
3600
						#設置錯誤識別
3600
						#設置錯誤識別
3601
						$result["status"]="false";
3601
						$result["status"]="false";
3602
						
3602
 
3603
						#設置錯誤訊息
3603
						#設置錯誤訊息
3604
						$result["error"]=$spiltString;
3604
						$result["error"]=$spiltString;
3605
						
3605
 
3606
						#debug
3606
						#debug
3607
						var_dump(__LINE__,$resutl);
3607
						var_dump(__LINE__,$resutl);
3608
						
3608
 
3609
						#回傳結果
3609
						#回傳結果
3610
						return $result;
3610
						return $result;
3611
					
3611
 
3612
						}#if end
3612
						}#if end
3613
						
3613
 
3614
					#如果沒有應該要存在的關鍵字
3614
					#如果沒有應該要存在的關鍵字
3615
					if($spiltString["found"]==="false"){
3615
					if($spiltString["found"]==="false"){
3616
					
3616
 
3617
						#設置錯誤識別
3617
						#設置錯誤識別
3618
						$result["status"]="false";
3618
						$result["status"]="false";
3619
						
3619
 
3620
						#設置錯誤訊息
3620
						#設置錯誤訊息
3621
						$result["error"]=$spiltString;
3621
						$result["error"]=$spiltString;
3622
						
3622
 
3623
						#debug
3623
						#debug
3624
						var_dump(__LINE__,$result);
3624
						var_dump(__LINE__,$result);
3625
						
3625
 
3626
						#回傳結果
3626
						#回傳結果
3627
						return $result;
3627
						return $result;
3628
					
3628
 
3629
						}#if end
3629
						}#if end
3630
					
3630
 
3631
					#如果沒有切割出2兩段以上
3631
					#如果沒有切割出2兩段以上
3632
					if($spiltString["dataCounts"]<2){
3632
					if($spiltString["dataCounts"]<2){
3633
					
3633
 
3634
						#設置錯誤識別
3634
						#設置錯誤識別
3635
						$result["status"]="false";
3635
						$result["status"]="false";
3636
						
3636
 
3637
						#設置錯誤訊息
3637
						#設置錯誤訊息
3638
						$result["error"]=$spiltString;
3638
						$result["error"]=$spiltString;
3639
						
3639
 
3640
						#debug
3640
						#debug
3641
						var_dump(__LINE__,$result);
3641
						var_dump(__LINE__,$result);
3642
						
3642
 
3643
						#回傳結果
3643
						#回傳結果
3644
						return $result;
3644
						return $result;
3645
					
3645
 
3646
						}#if end
3646
						}#if end
3647
					
3647
 
3648
					#取得解析好的來源(urlencoded)
3648
					#取得解析好的來源(urlencoded)
3649
					$server=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
3649
					$server=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
3650
					
3650
 
3651
					#函式說明:
3651
					#函式說明:
3652
					#將字串特定關鍵字與其後面的內容剔除
3652
					#將字串特定關鍵字與其後面的內容剔除
3653
					#回傳結果:
3653
					#回傳結果:
3654
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3654
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3655
					#$result["error"],錯誤訊息陣列.
3655
					#$result["error"],錯誤訊息陣列.
Line 3671... Line 3671...
3671
					#無.
3671
					#無.
3672
					#備註:
3672
					#備註:
3673
					#無.
3673
					#無.
3674
					$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
3674
					$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
3675
					unset($conf["stringProcess::delStrAfterKeyWord"]);
3675
					unset($conf["stringProcess::delStrAfterKeyWord"]);
3676
					
3676
 
3677
					#如果執行失敗
3677
					#如果執行失敗
3678
					if($delStrAfterKeyWord["status"]==="false"){
3678
					if($delStrAfterKeyWord["status"]==="false"){
3679
					
3679
 
3680
						#設置錯誤識別
3680
						#設置錯誤識別
3681
						$result["status"]="false";
3681
						$result["status"]="false";
3682
						
3682
 
3683
						#設置錯誤訊息
3683
						#設置錯誤訊息
3684
						$result["error"]=$delStrAfterKeyWord;
3684
						$result["error"]=$delStrAfterKeyWord;
3685
						
3685
 
3686
						#debug
3686
						#debug
3687
						var_dump(__LINE__,$result);
3687
						var_dump(__LINE__,$result);
3688
						
3688
 
3689
						#回傳結果
3689
						#回傳結果
3690
						return $result;
3690
						return $result;
3691
					
3691
 
3692
						}#if end
3692
						}#if end
3693
						
3693
 
3694
					#如果沒有關鍵字
3694
					#如果沒有關鍵字
3695
					if($delStrAfterKeyWord["founded"]==="false"){
3695
					if($delStrAfterKeyWord["founded"]==="false"){
3696
					
3696
 
3697
						#設置錯誤識別
3697
						#設置錯誤識別
3698
						$result["status"]="false";
3698
						$result["status"]="false";
3699
						
3699
 
3700
						#設置錯誤訊息
3700
						#設置錯誤訊息
3701
						$result["error"]=$delStrAfterKeyWord;
3701
						$result["error"]=$delStrAfterKeyWord;
3702
						
3702
 
3703
						#debug
3703
						#debug
3704
						var_dump(__LINE__,$resutl);
3704
						var_dump(__LINE__,$resutl);
3705
						
3705
 
3706
						#回傳結果
3706
						#回傳結果
3707
						return $result;
3707
						return $result;
3708
					
3708
 
3709
						}#if end
3709
						}#if end
3710
					
3710
 
3711
					#另存postName與server的字串
3711
					#另存postName與server的字串
3712
					$postName=$delStrAfterKeyWord["content"];
3712
					$postName=$delStrAfterKeyWord["content"];
3713
					
3713
 
3714
					#解析對應的 postName 與 server - end
3714
					#解析對應的 postName 與 server - end
3715
					
3715
 
3716
					#如果對應該cache檔案的cache不存在
3716
					#如果對應該cache檔案的cache不存在
3717
					if(!isset($conf["serverCache"]["clientSide"]["share"]["configs"][urldecode($server)][$postName])){
3717
					if(!isset($conf["serverCache"]["clientSide"]["share"]["configs"][urldecode($server)][$postName])){
3718
					
3718
 
3719
						#讀取其json
3719
						#讀取其json
3720
						#函式說明:
3720
						#函式說明:
3721
						#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
3721
						#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
3722
						#回傳的變數說明:
3722
						#回傳的變數說明:
3723
						#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
3723
						#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
Line 3748... Line 3748...
3748
						#無.
3748
						#無.
3749
						#備註:
3749
						#備註:
3750
						#無.
3750
						#無.
3751
						$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
3751
						$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
3752
						unset($conf["fileAccess::getFileContent"]);
3752
						unset($conf["fileAccess::getFileContent"]);
3753
					
3753
 
3754
						#如果執行失敗
3754
						#如果執行失敗
3755
						if($getFileContent["status"]==="false"){
3755
						if($getFileContent["status"]==="false"){
3756
						
3756
 
3757
							#設置錯誤識別
3757
							#設置錯誤識別
3758
							$result["status"]="false";
3758
							$result["status"]="false";
3759
							
3759
 
3760
							#設置錯誤訊息
3760
							#設置錯誤訊息
3761
							$result["error"]=$getFileContent;
3761
							$result["error"]=$getFileContent;
3762
							
3762
 
3763
							#debug
3763
							#debug
3764
							var_dump(__LINE__,$result);
3764
							var_dump(__LINE__,$result);
3765
							
3765
 
3766
							#回傳結果
3766
							#回傳結果
3767
							return $result;
3767
							return $result;
3768
						
3768
 
3769
							}#if end
3769
							}#if end
3770
 
3770
 
3771
						#debug
3771
						#debug
3772
						#var_dump(__LINE__,$getFileContent);
3772
						#var_dump(__LINE__,$getFileContent);
3773
 
3773
 
3774
						#set json string content
3774
						#set json string content
3775
						$conf["serverCache"]["clientSide"]["share"]["configs"][urldecode($server)][$postName]["content"]=$getFileContent["fullContent"];
3775
						$conf["serverCache"]["clientSide"]["share"]["configs"][urldecode($server)][$postName]["content"]=$getFileContent["fullContent"];
3776
						
3776
 
3777
						#設置已經有 cache 成檔案
3777
						#設置已經有 cache 成檔案
3778
						$conf["serverCache"]["clientSide"]["share"]["configs"][urldecode($server)][$postName]["cachedFile"]="true";
3778
						$conf["serverCache"]["clientSide"]["share"]["configs"][urldecode($server)][$postName]["cachedFile"]="true";
3779
						
3779
 
3780
						#set cached file
3780
						#set cached file
3781
						$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["cachedFile"][]=$nodeInfo["name"];
3781
						$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["cachedFile"][]=$nodeInfo["name"];
3782
						
3782
 
3783
						#debug
3783
						#debug
3784
						#var_dump(__LINE__,$conf["serverCache"]);
3784
						#var_dump(__LINE__,$conf["serverCache"]);
3785
						
3785
 
3786
						}#if end
3786
						}#if end
3787
				
3787
 
3788
					}#if end
3788
					}#if end
3789
			
3789
 
3790
				}#if end
3790
				}#if end
3791
		
3791
 
3792
			}#foreach end
3792
			}#foreach end
3793
		
3793
 
3794
		#檢查有每個 cache 檔案,若沒有對應的 clientCache,則cache 之. - end
3794
		#檢查有每個 cache 檔案,若沒有對應的 clientCache,則cache 之. - end
3795
		
3795
 
3796
		#檢查每個 clientCache 若過期則更新之. - start
3796
		#檢查每個 clientCache 若過期則更新之. - start
3797
		
3797
 
3798
		#如果沒有 $conf["serverCache"]["clientSide"]["share"]
3798
		#如果沒有 $conf["serverCache"]["clientSide"]["share"]
3799
		if(!isset($conf["serverCache"]["clientSide"]["share"])){
3799
		if(!isset($conf["serverCache"]["clientSide"]["share"])){
3800
		
3800
 
3801
			#初始化之
3801
			#初始化之
3802
			$conf["serverCache"]["clientSide"]["share"]["configs"]=array();
3802
			$conf["serverCache"]["clientSide"]["share"]["configs"]=array();
3803
		
3803
 
3804
			}#if end
3804
			}#if end
3805
		
3805
 
3806
		#針對每個 client site 的 share configs 變數
3806
		#針對每個 client site 的 share configs 變數
3807
		foreach($conf["serverCache"]["clientSide"]["share"]["configs"] as $serverUrl => $postNames){
3807
		foreach($conf["serverCache"]["clientSide"]["share"]["configs"] as $serverUrl => $postNames){
3808
		
3808
 
3809
			#針對該site每個config資訊
3809
			#針對該site每個config資訊
3810
			foreach($postNames as $configName => $configVal){
3810
			foreach($postNames as $configName => $configVal){
3811
		
3811
 
3812
				#如果沒有最後更新時間
3812
				#如果沒有最後更新時間
3813
				if(!isset($postNames["time"])){
3813
				if(!isset($postNames["time"])){
3814
				
3814
 
3815
					#設置最後更新時間
3815
					#設置最後更新時間
3816
					$conf["serverCache"]["clientSide"]["share"]["configs"][$serverUrl][$configName]["time"]=time();
3816
					$conf["serverCache"]["clientSide"]["share"]["configs"][$serverUrl][$configName]["time"]=time();
3817
				
3817
 
3818
					#換下一個 postName
3818
					#換下一個 postName
3819
					continue;
3819
					continue;
3820
				
3820
 
3821
					}#if end
3821
					}#if end
3822
		
3822
 
3823
				#如果過期了
3823
				#如果過期了
3824
				if( time()-$postNames["time"]>$checkVersionInterval ){
3824
				if( time()-$postNames["time"]>$checkVersionInterval ){
3825
				
3825
 
3826
					#嘗試從網路取得config
3826
					#嘗試從網路取得config
3827
					#函式說明:
3827
					#函式說明:
3828
					#查尋有使用 server 函式提供組態設定檔的服務,取得key的value.
3828
					#查尋有使用 server 函式提供組態設定檔的服務,取得key的value.
3829
					#回傳結果:
3829
					#回傳結果:
3830
					#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
3830
					#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
Line 3850... Line 3850...
3850
					#無.
3850
					#無.
3851
					#備註:
3851
					#備註:
3852
					#目前僅能跟server函式提供的服務對接.
3852
					#目前僅能跟server函式提供的服務對接.
3853
					$client=config::client($conf["config::client"]);
3853
					$client=config::client($conf["config::client"]);
3854
					unset($conf["config::client"]);
3854
					unset($conf["config::client"]);
3855
					
3855
 
3856
					#若從網路取得成功
3856
					#若從網路取得成功
3857
					if($client["status"]==="true"){
3857
					if($client["status"]==="true"){
3858
						
3858
 
3859
						#另存來源
3859
						#另存來源
3860
						$client["content"]["server"]=$serverUrl;
3860
						$client["content"]["server"]=$serverUrl;
3861
						
3861
 
3862
						#另存 configName
3862
						#另存 configName
3863
						$client["content"]["postName"]=$configName;
3863
						$client["content"]["postName"]=$configName;
3864
						
3864
 
3865
						#儲存起來下次再看跑完沒
3865
						#儲存起來下次再看跑完沒
3866
						$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"][]=$client["content"];
3866
						$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"][]=$client["content"];
3867
						
3867
 
3868
						#換處理下個 configName
3868
						#換處理下個 configName
3869
						continue;
3869
						continue;
3870
					
3870
 
3871
						}#if end	
3871
						}#if end
3872
						
3872
 
3873
					#執行到這邊代表從網路取得失敗
3873
					#執行到這邊代表從網路取得失敗
3874
					
3874
 
3875
					#將事件記錄起來
3875
					#將事件記錄起來
3876
					var_dump(__FILE__,__LINE__,$client);
3876
					var_dump(__FILE__,__LINE__,$client);
3877
				
3877
 
3878
					}#if end
3878
					}#if end
3879
		
3879
 
3880
				}#foreach end
3880
				}#foreach end
3881
	
3881
 
3882
			}#foreach end
3882
			}#foreach end
3883
		
3883
 
3884
		#檢查每個 clientCache 若過期則更新之. - end
3884
		#檢查每個 clientCache 若過期則更新之. - end
3885
		
3885
 
3886
		#檢查每個 clientCache 若無對應 cache file 則產生之. - start
3886
		#檢查每個 clientCache 若無對應 cache file 則產生之. - start
3887
		
3887
 
3888
		#針對每個 client site 的 share configs 變數
3888
		#針對每個 client site 的 share configs 變數
3889
		foreach($conf["serverCache"]["clientSide"]["share"]["configs"] as $serverUrl => $postNames){
3889
		foreach($conf["serverCache"]["clientSide"]["share"]["configs"] as $serverUrl => $postNames){
3890
		
3890
 
3891
			#針對該site每個postName資訊
3891
			#針對該site每個postName資訊
3892
			foreach($postNames as $configName => $configVal){
3892
			foreach($postNames as $configName => $configVal){
3893
			
3893
 
3894
				#expected cache file name
3894
				#expected cache file name
3895
				#$cacheFilePath."client::config-cache-".$configName." from ".$serverUrl.".json";
3895
				#$cacheFilePath."client::config-cache-".$configName." from ".$serverUrl.".json";
3896
				
3896
 
3897
				#realistic cache file name
3897
				#realistic cache file name
3898
				#$cacheFilePath."client::config-cache-".urlencode($configName)." from ".urlencode($serverUrl).".json";
3898
				#$cacheFilePath."client::config-cache-".urlencode($configName)." from ".urlencode($serverUrl).".json";
3899
				
3899
 
3900
				#函式說明:
3900
				#函式說明:
3901
				#檢查多個檔案與資料夾是否存在.
3901
				#檢查多個檔案與資料夾是否存在.
3902
				#回傳的結果:
3902
				#回傳的結果:
3903
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3903
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3904
				#$result["error"],錯誤訊息陣列.
3904
				#$result["error"],錯誤訊息陣列.
Line 3927... Line 3927...
3927
				#備註:
3927
				#備註:
3928
				#函數file_exists檢查的路徑為檔案系統的路徑
3928
				#函數file_exists檢查的路徑為檔案系統的路徑
3929
				#$result["varName"][$i]結果未實作
3929
				#$result["varName"][$i]結果未實作
3930
				$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
3930
				$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
3931
				unset($conf["fileAccess::checkMultiFileExist"]);
3931
				unset($conf["fileAccess::checkMultiFileExist"]);
3932
			
3932
 
3933
				#如果執行失敗
3933
				#如果執行失敗
3934
				if($checkMultiFileExist["status"]==="false"){
3934
				if($checkMultiFileExist["status"]==="false"){
3935
				
3935
 
3936
					#設置錯誤識別
3936
					#設置錯誤識別
3937
					$result["status"]="false";
3937
					$result["status"]="false";
3938
					
3938
 
3939
					#設置錯誤訊息
3939
					#設置錯誤訊息
3940
					$result["error"]=$checkMultiFileExist;
3940
					$result["error"]=$checkMultiFileExist;
3941
					
3941
 
3942
					#debug
3942
					#debug
3943
					var_dump(__LINE__,$result);
3943
					var_dump(__LINE__,$result);
3944
					
3944
 
3945
					#回傳結果
3945
					#回傳結果
3946
					return $result;
3946
					return $result;
3947
				
3947
 
3948
					}#if end
3948
					}#if end
3949
			
3949
 
3950
				#如果 cache file 不存在
3950
				#如果 cache file 不存在
3951
				if($checkMultiFileExist["allExist"]==="false"){
3951
				if($checkMultiFileExist["allExist"]==="false"){
3952
				
3952
 
3953
					#函式說明:
3953
					#函式說明:
3954
					#將字串寫入到檔案
3954
					#將字串寫入到檔案
3955
					#回傳結果:
3955
					#回傳結果:
3956
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
3956
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
3957
					#$result["error"],錯誤訊息陣列.
3957
					#$result["error"],錯誤訊息陣列.
Line 3983... Line 3983...
3983
					#無.
3983
					#無.
3984
					#備註:
3984
					#備註:
3985
					#無.
3985
					#無.
3986
					$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
3986
					$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
3987
					unset($conf["fileAccess::writeTextIntoFile"]);
3987
					unset($conf["fileAccess::writeTextIntoFile"]);
3988
				
3988
 
3989
					#如果執行失敗
3989
					#如果執行失敗
3990
					if($writeTextIntoFile["status"]==="false"){
3990
					if($writeTextIntoFile["status"]==="false"){
3991
					
3991
 
3992
						#設置錯誤識別
3992
						#設置錯誤識別
3993
						$result["status"]="false";
3993
						$result["status"]="false";
3994
						
3994
 
3995
						#設置錯誤訊息
3995
						#設置錯誤訊息
3996
						$result["error"]=$writeTextIntoFile;
3996
						$result["error"]=$writeTextIntoFile;
3997
						
3997
 
3998
						#debug
3998
						#debug
3999
						var_dump(__LINE__,$result);
3999
						var_dump(__LINE__,$result);
4000
						
4000
 
4001
						#回傳結果
4001
						#回傳結果
4002
						return $result;
4002
						return $result;
4003
					
4003
 
4004
						}#if end
4004
						}#if end
4005
						
4005
 
4006
					#設置已經有 cache 成檔案
4006
					#設置已經有 cache 成檔案
4007
					$conf["serverCache"]["clientSide"]["share"]["configs"][$serverUrl][$configName]["cachedFile"]="true";
4007
					$conf["serverCache"]["clientSide"]["share"]["configs"][$serverUrl][$configName]["cachedFile"]="true";
4008
						
4008
 
4009
					#set cached file
4009
					#set cached file
4010
					$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["cachedFile"][]="client::config-cache-".urlencode($configName)." from ".urlencode($serverUrl).".json";
4010
					$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["cachedFile"][]="client::config-cache-".urlencode($configName)." from ".urlencode($serverUrl).".json";
4011
				
4011
 
4012
					}#if end
4012
					}#if end
4013
			
4013
 
4014
				}#foreach end
4014
				}#foreach end
4015
				
4015
 
4016
			}#foreach end
4016
			}#foreach end
4017
	
4017
 
4018
		#檢查每個 clientCache 若無對應 cache file 則產生之. - end
4018
		#檢查每個 clientCache 若無對應 cache file 則產生之. - end
4019
		
4019
 
4020
		#設置執行正常
4020
		#設置執行正常
4021
		$result["status"]="true";
4021
		$result["status"]="true";
4022
		
4022
 
4023
		#回傳結果
4023
		#回傳結果
4024
		return $result;
4024
		return $result;
4025
	
4025
 
4026
		}#function funcToRunWhenIdleForClientCacheDaemon end
4026
		}#function funcToRunWhenIdleForClientCacheDaemon end
4027
	
4027
 
4028
	/*
4028
	/*
4029
	#函式說明:
4029
	#函式說明:
4030
	#處理來自config::client有使用cache的要求,其為常駐的unix domain socket
4030
	#處理來自config::client有使用cache的要求,其為常駐的unix domain socket
4031
	#回傳結果:
4031
	#回傳結果:
4032
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
4032
	#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
Line 4045... Line 4045...
4045
	#無.
4045
	#無.
4046
	#備註:
4046
	#備註:
4047
	#無,
4047
	#無,
4048
	*/
4048
	*/
4049
	public static function clientCacheDaemon(&$conf){
4049
	public static function clientCacheDaemon(&$conf){
4050
	 
4050
 
4051
		#初始化要回傳的結果
4051
		#初始化要回傳的結果
4052
		$result=array();
4052
		$result=array();
4053
 
4053
 
4054
		#取得當前執行的函數名稱
4054
		#取得當前執行的函數名稱
4055
		$result["function"]=__FUNCTION__;
4055
		$result["function"]=__FUNCTION__;
Line 4076... Line 4076...
4076
 
4076
 
4077
			#回傳結果
4077
			#回傳結果
4078
			return $result;
4078
			return $result;
4079
 
4079
 
4080
			}#if end
4080
			}#if end
4081
	
4081
 
4082
		#函式說明:
4082
		#函式說明:
4083
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
4083
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
4084
		#回傳結果:
4084
		#回傳結果:
4085
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4085
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4086
		#$result["error"],執行不正常結束的錯訊息陣列.
4086
		#$result["error"],執行不正常結束的錯訊息陣列.
Line 4131... Line 4131...
4131
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4131
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4132
		#備註:
4132
		#備註:
4133
		#無.
4133
		#無.
4134
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4134
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4135
		unset($conf["variableCheck::checkArguments"]);
4135
		unset($conf["variableCheck::checkArguments"]);
4136
	
4136
 
4137
		#如果執行失敗
4137
		#如果執行失敗
4138
		if($checkArguments["status"]==="false"){
4138
		if($checkArguments["status"]==="false"){
4139
		
4139
 
4140
			#設置錯誤識別
4140
			#設置錯誤識別
4141
			$result["status"]="false";
4141
			$result["status"]="false";
4142
			
4142
 
4143
			#設置錯誤訊息
4143
			#設置錯誤訊息
4144
			$result["error"]=$checkArguments;
4144
			$result["error"]=$checkArguments;
4145
			
4145
 
4146
			#回傳結果
4146
			#回傳結果
4147
			return $result;
4147
			return $result;
4148
		
4148
 
4149
			}#if end
4149
			}#if end
4150
			
4150
 
4151
		#如果檢查不通過
4151
		#如果檢查不通過
4152
		if($checkArguments["passed"]==="false"){
4152
		if($checkArguments["passed"]==="false"){
4153
		
4153
 
4154
			#設置錯誤識別
4154
			#設置錯誤識別
4155
			$result["status"]="false";
4155
			$result["status"]="false";
4156
			
4156
 
4157
			#設置錯誤訊息
4157
			#設置錯誤訊息
4158
			$result["error"]=$checkArguments;
4158
			$result["error"]=$checkArguments;
4159
			
4159
 
4160
			#回傳結果
4160
			#回傳結果
4161
			return $result;
4161
			return $result;
4162
		
4162
 
4163
			}#if end
4163
			}#if end
4164
		
4164
 
4165
		#函式說明:
4165
		#函式說明:
4166
		#取得目前瀏覽的頁面的路徑或執行的php程式路徑.
4166
		#取得目前瀏覽的頁面的路徑或執行的php程式路徑.
4167
		#回傳結果:
4167
		#回傳結果:
4168
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
4168
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
4169
		#$result["error"],錯誤訊息.
4169
		#$result["error"],錯誤訊息.
Line 4181... Line 4181...
4181
		#http://blog.longwin.com.tw/2009/01/php-get-directory-file-path-dirname-2008/
4181
		#http://blog.longwin.com.tw/2009/01/php-get-directory-file-path-dirname-2008/
4182
		#備註:
4182
		#備註:
4183
		#無.
4183
		#無.
4184
		$getPathOfThisPhpFile=csInformation::getPathOfThisPhpFile($conf["csInformation::getPathOfThisPhpFile"]);
4184
		$getPathOfThisPhpFile=csInformation::getPathOfThisPhpFile($conf["csInformation::getPathOfThisPhpFile"]);
4185
		unset($conf["csInformation::getPathOfThisPhpFile"]);
4185
		unset($conf["csInformation::getPathOfThisPhpFile"]);
4186
	
4186
 
4187
		#如果執行失敗
4187
		#如果執行失敗
4188
		if($getPathOfThisPhpFile["status"]=="false"){
4188
		if($getPathOfThisPhpFile["status"]=="false"){
4189
			
4189
 
4190
			#設置錯誤識別
4190
			#設置錯誤識別
4191
			$result["status"]="false";
4191
			$result["status"]="false";
4192
			
4192
 
4193
			#設置錯誤訊息
4193
			#設置錯誤訊息
4194
			$result["error"]=$getPathOfThisPhpFile;
4194
			$result["error"]=$getPathOfThisPhpFile;
4195
			
4195
 
4196
			#回傳結果
4196
			#回傳結果
4197
			return $result;
4197
			return $result;
4198
			
4198
 
4199
			}#if end
4199
			}#if end
4200
			
4200
 
4201
		#如果沒有設定 sock
4201
		#如果沒有設定 sock
4202
		if(!isset($conf["sock"])){
4202
		if(!isset($conf["sock"])){
4203
		
4203
 
4204
			#設置預設的cache檔案名稱
4204
			#設置預設的cache檔案名稱
4205
			$conf["sock"]=$getPathOfThisPhpFile["content"]."var/config::client/clientCacheDaemon.sock";
4205
			$conf["sock"]=$getPathOfThisPhpFile["content"]."var/config::client/clientCacheDaemon.sock";
4206
			
4206
 
4207
			}#if end
4207
			}#if end
4208
		
4208
 
4209
		#如果 無設置 cacheFilePath
4209
		#如果 無設置 cacheFilePath
4210
		if(!isset($conf["cacheFilePath"])){
4210
		if(!isset($conf["cacheFilePath"])){
4211
		
4211
 
4212
			#設置預設的 cacheFilePath 
4212
			#設置預設的 cacheFilePath
4213
			$conf["cacheFilePath"]=$getPathOfThisPhpFile["content"]."var/config::client/";
4213
			$conf["cacheFilePath"]=$getPathOfThisPhpFile["content"]."var/config::client/";
4214
		
4214
 
4215
			}#if end
4215
			}#if end
4216
		
4216
 
4217
		#函式說明:
4217
		#函式說明:
4218
		#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.
4218
		#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.
4219
		#回傳結果:
4219
		#回傳結果:
4220
		#$result["status"],"true"代表執行正常;"false"代表執行不正常.
4220
		#$result["status"],"true"代表執行正常;"false"代表執行不正常.
4221
		#$result["error"],錯誤訊息陣列.
4221
		#$result["error"],錯誤訊息陣列.
Line 4247... Line 4247...
4247
		#http://php.net/manual/en/function.stream-socket-server.php
4247
		#http://php.net/manual/en/function.stream-socket-server.php
4248
		#備註:
4248
		#備註:
4249
		#無.
4249
		#無.
4250
		$unixDomainSockServer=sock::unixDomainSockServer($conf["sock::unixDomainSockServer"]);
4250
		$unixDomainSockServer=sock::unixDomainSockServer($conf["sock::unixDomainSockServer"]);
4251
		unset($conf["sock::unixDomainSockServer"]);
4251
		unset($conf["sock::unixDomainSockServer"]);
4252
		
4252
 
4253
		#如果執行失敗
4253
		#如果執行失敗
4254
		if($unixDomainSockServer["status"]==="false"){
4254
		if($unixDomainSockServer["status"]==="false"){
4255
			
4255
 
4256
			#設置錯誤識別
4256
			#設置錯誤識別
4257
			$result["status"]="false";
4257
			$result["status"]="false";
4258
			
4258
 
4259
			#設置錯誤訊息
4259
			#設置錯誤訊息
4260
			$result["error"]=$unixDomainSockServer;
4260
			$result["error"]=$unixDomainSockServer;
4261
			
4261
 
4262
			#回傳結果
4262
			#回傳結果
4263
			return $result;
4263
			return $result;
4264
			
4264
 
4265
			}#if end
4265
			}#if end
4266
	
4266
 
4267
		}#function clientCacheDaemon end
4267
		}#function clientCacheDaemon end
4268
	
4268
 
4269
	}#class config end
4269
	}#class config end
4270
 
4270
 
4271
?>
-
 
4272
4271
?>
-
 
4272