Subversion Repositories php-qbpwcf

Rev

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

Rev Author Line No. Line
306 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
namespace qbpwcf;
25
 
327 liveuser 26
/*
27
類別說明:
28
提供資料與具備揮發性的物件、資源管理,讓不同程序與程式甚至不同語言都能夠共享資源.
29
備註:
30
無.
31
*/
306 liveuser 32
class resource{
33
 
34
	/*
35
	#函式說明:
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
37
	#回傳結果:
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
39
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
40
	#$result["function"],當前執行的函式名稱.
41
	#必填參數:
42
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
44
	#可省略參數:
45
	#無.
46
	#參考資料:
47
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
48
	#備註:
327 liveuser 49
	#無.
306 liveuser 50
	*/
51
	public function __call($method,$arguments){
52
 
53
		#取得當前執行的函式
54
		$result["function"]=__FUNCTION__;
55
 
56
		#設置執行不正常
57
		$result["status"]="false";
58
 
59
		#設置執行錯誤
60
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
61
 
62
		#設置所丟入的參數
63
		$result["error"][]=$arguments;
64
 
65
		#回傳結果
66
		return $result;
67
 
68
		}#function __call end
69
 
70
	/*
71
	#函式說明:
72
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
73
	#回傳結果:
74
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
75
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
76
	#$result["function"],當前執行的函式名稱.
77
	#必填參數:
78
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
79
	#$arguments,陣列,為呼叫方法時所用的參數.
80
	#可省略參數:
81
	#無.
82
	#參考資料:
83
	#__callStatic=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
84
	#備註:
327 liveuser 85
	#無.
306 liveuser 86
	*/
87
	public static function __callStatic($method,$arguments){
88
 
89
		#取得當前執行的函式
90
		$result["function"]=__FUNCTION__;
91
 
92
		#設置執行不正常
93
		$result["status"]="false";
94
 
95
		#設置執行錯誤
96
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
97
 
98
		#設置所丟入的參數
99
		$result["error"][]=$arguments;
100
 
101
		#回傳結果
102
		return $result;
103
 
104
		}#function __callStatic end
105
 
106
	/*
107
	#函式說明:
327 liveuser 108
	#建立快取服務.實質上為unix domain socket server.
109
	#回傳結果:
110
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
111
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
112
	#$result["function"],當前執行的函式名稱.
113
	#$result["argu"],所使用的參數.
306 liveuser 114
	#必填參數:
327 liveuser 115
	#無.
116
	#可省略參數:
117
	#$conf["sock"],字串,unix domain socket的路徑與名稱,預設為相對於當前套件的 var/qbpwcf/resource.sock
118
	#$conf["sock"]="";
119
	#$conf["debug"],字串,"true"代表要啟用debug模式;反之預設為"false"不啟用.
120
	#$conf["debug"]="";
368 liveuser 121
	#$conf["addOnProcessFunc"],陣列,收到訊息後,要依順執行的函式,預設為array("\qbpwcf\resource::addOnProcessFunc"),會傳遞的參數為一陣列,每個元素的key與value依序為"id":"識別用戶的id";"last_request_time":"訊號來的時間";"request":"收到的訊息陣列";"socket":"跟用戶互動用socket";"clientCache":id對應用戶的cache;
327 liveuser 122
	#$conf["addOnProcessFunc"]=array();
339 liveuser 123
	#$conf["funcToRunWhenIdle"],陣列,閒置時要依序執行的函式,預設為array("/qbpwcf/resource::funcToRunWhenIdle");
327 liveuser 124
	#$conf["funcToRunWhenIdle"]=array();
339 liveuser 125
	#$conf["deafaultLifeTime"],字串,資源沒被使用時,預設的存留時間秒數,預設為"300".
126
	#$conf["deafaultLifeTime"]="300";
368 liveuser 127
	#$conf["defaultUserGroup"],字串,unix domain socket的擁有者與群組為何,預設為"root.".webUser.
128
	#$ocnf["defaultUserGroup"]="root.".webUser;
129
	#$conf["defaultPermission"],字串,unix domain socket的權限設定,預設為"0660",代表擁有者與其群組有讀寫的權限.
130
	#$conf["defaultPermission"]="0660";
306 liveuser 131
	#參考資料:
327 liveuser 132
	#無.
306 liveuser 133
	#備註:
327 liveuser 134
	#僅能在命令列環境下運行.
306 liveuser 135
	*/
136
	public static function server(&$conf){
137
 
138
		#初始化要回傳的結果
139
		$result=array();
140
 
141
		#取得當前執行的函數名稱
142
		$result["function"]=__FUNCTION__;
143
 
144
		#如果沒有參數
145
		if(func_num_args()==0){
146
 
147
			#設置執行失敗
148
			$result["status"]="false";
149
 
150
			#設置執行錯誤訊息
151
			$result["error"]="函數".$result["function"]."需要參數";
152
 
153
			#回傳結果
154
			return $result;
155
 
156
			}#if end
157
 
158
		#涵式說明:
159
		#判斷當前環境為web還是cmd
160
		#回傳結果:
161
		#$result,"web"或"cmd"
162
		if(csInformation::getEnv()==="web"){
163
 
164
			#設置執行失敗
165
			$result["status"]="false";
166
 
167
			#設置執行錯誤訊息
168
			$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
169
 
170
			#回傳結果
171
			return $result;
172
 
173
			}#if end
327 liveuser 174
 
306 liveuser 175
		#取得參數
176
		$result["argu"]=$conf;
177
 
178
		#如果 $conf 不為陣列
179
		if(gettype($conf)!=="array"){
180
 
181
			#設置執行失敗
182
			$result["status"]="false";
183
 
184
			#設置執行錯誤訊息
185
			$result["error"][]="\$conf變數須為陣列形態";
186
 
187
			#如果傳入的參數為 null
188
			if(is_null($conf)){
189
 
190
				#設置執行錯誤訊息
191
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
192
 
193
				}#if end
194
 
195
			#回傳結果
196
			return $result;
197
 
198
			}#if end
327 liveuser 199
 
306 liveuser 200
		#預設的 unix domain socket addr
327 liveuser 201
		$sock=pathinfo(__FILE__)["dirname"]."/../../var/qbpwcf/resource.sock";
202
 
306 liveuser 203
		#檢查參數
204
		#函式說明:
205
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
206
		#回傳結果:
207
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
208
		#$result["error"],執行不正常結束的錯訊息陣列.
209
		#$result["simpleError"],簡單表示的錯誤訊息.
210
		#$result["function"],當前執行的函式名稱.
211
		#$result["argu"],設置給予的參數.
212
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
213
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
214
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
215
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
216
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
217
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
218
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
219
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
220
		#必填參數:
221
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
222
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
223
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
339 liveuser 224
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
306 liveuser 225
		#可省略參數:
226
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
327 liveuser 227
		#$conf["mustBeFilledVariableName"]=array();
306 liveuser 228
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
327 liveuser 229
		#$conf["mustBeFilledVariableType"]=array();
306 liveuser 230
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
231
		#$conf["canBeEmptyString"]="false";
232
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
233
		#$conf["canNotBeEmpty"]=array();
234
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
235
		#$conf["canBeEmpty"]=array();
236
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
368 liveuser 237
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sock","deafaultLifeTime","defaultUserGroup","defaultPermission");
306 liveuser 238
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
368 liveuser 239
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sock","deafaultLifeTime","defaultUserGroup","defaultPermission");
306 liveuser 240
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
368 liveuser 241
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
306 liveuser 242
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
368 liveuser 243
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($sock,"300","root.".webUser,"0660");
306 liveuser 244
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
245
		#$conf["disallowAllSkipableVarIsEmpty"]="";
246
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
247
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
248
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
327 liveuser 249
		#$conf["disallowAllSkipableVarNotExist"]="";
306 liveuser 250
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
251
		#$conf["arrayCountEqualCheck"][]=array();
252
		#參考資料:
253
		#array_keys=>http://php.net/manual/en/function.array-keys.php
254
		#備註:
255
		#無.
256
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
257
		unset($conf["variableCheck::checkArguments"]);
327 liveuser 258
 
306 liveuser 259
		#如果執行異常
260
		if($checkArguments["status"]==="false"){
327 liveuser 261
 
262
			#設置執行異常識別
263
			$result["status"]="false";
264
 
265
			#設置執行錯誤
266
			$result["error"]=$checkArguments;
267
 
268
			#回傳結果
269
			return $result;
270
 
271
			}#if end
272
 
273
		#初始化要儲存快取資料的變數
274
		$resource=array();
339 liveuser 275
 
276
		/*
277
		$resource 結構
278
		$resource[$uuid]["value"],資源的內容.
279
		$resource[$uuid]["type"],資源的類型,有php_variable跟proc.
280
		$resource[$uuid]["life"],資源的壽命,單位為秒數.
281
		*/
327 liveuser 282
 
283
		#函式說明:
284
		#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.
285
		#回傳結果:
286
		#$result["status"],"true"代表執行正常;"false"代表執行不正常.
287
		#$result["error"],錯誤訊息陣列.
288
		#$result["function"],當前執行的函式名稱.
289
		#$result["serverCache"],函式結束前,儲存在serverCache的內容,若有元素"exit"存在則代表是正常結束.
290
		#$result["serverCache"]["serverSide"],server side 的 cache.
291
		#$result["serverCache"]["serverSide"]["procs"], server side 的 procs cache,儲存執行的子程序資訊.
292
		#$result["serverCache"]["clientSide"],client site 的 cache.
293
		#必填參數:
294
		#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.
295
		$conf["sock::unixDomainSockServer"]["sock"]=$conf["sock"];
296
		#$conf["fileArgu"],字串,變數__FILE__的內容.
297
		$conf["sock::unixDomainSockServer"]["fileArgu"]=__FILE__;
298
		#可省略參數:
299
		#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.
368 liveuser 300
		$conf["sock::unixDomainSockServer"]["changeOwner"]=$conf["defaultUserGroup"];
327 liveuser 301
		#$conf["changePermission"],字串,要將socket檔案的權限設為多少.ex: "0666"(所有帳戶都有存取的權限) 或 "0660"(僅有擁有者與群組帳戶有存取的權限) 或 "0600"(只有擁有者有權限執行).
368 liveuser 302
		$conf["sock::unixDomainSockServer"]["changePermission"]=$conf["defaultPermission"];
327 liveuser 303
		#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.
304
		#$conf["sessionTimeout"]="300";
305
		#$conf["addOnProcessFunc"],字串陣列,增加用於處理 json request 的函式名稱,給予的參數為array("request"=>收到的json訊息,"sock"=>用戶的socket,"clientCache"=>給予所有用戶的cache),若收到的不是json而是"quit"則代表用戶要結束連線;若收到的是$shutdownStr則代表要結束本函式.回傳的內容必須為陣列,例如 $res["continue"]="true"代表要繼續執行下一個addOnProcessFunc;"false"代表代表到此為止. $res["content"]="replaced content";代表要將收到的訊息取代成"replaced content". 最少要有回傳 $res["status"]數值"true"代表執行正常;"false"代表執行不正常.
306
		$conf["sock::unixDomainSockServer"]["addOnProcessFunc"]=array("\qbpwcf\\resource::addOnProcessFunc");
307
		#$conf["funcToRunWhenIdle"],字串陣列,當沒有事件產生時,要執行的函式名稱,給予參數為array("client"=>所有用戶,"clientCache"=>$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"serverCache"=>$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle]).
308
		$conf["sock::unixDomainSockServer"]["funcToRunWhenIdle"]=array("\qbpwcf\\resource::funcToRunWhenIdle");
309
		#$conf["paramsForFuncToRunWhenIdle"],2維陣列,每個元素代表指定給予funcToRunWhenIdle參數中的指定元素的參數.
310
		#$conf["paramsForFuncToRunWhenIdle"]=array();
311
		#$conf["infoToFunction"],陣列,需要增加給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
339 liveuser 312
		$conf["sock::unixDomainSockServer"]["infoToFunction"]=array("resource"=>$resource,"defaultLifeTime"=>$conf["deafaultLifeTime"]);
327 liveuser 313
		#$conf["shutdownStrAddr"],字串,儲存收到用戶傳什麼樣的字串會結束本函式的檔案位置與名稱,預設為 $conf["sock"].".shutdown".
314
		#$conf["shutdownStrAddr"]="";
339 liveuser 315
		#$conf["shutdownCallback"],字串,當收到 shutdownStrAddr 參數的字串後,會先執行該函式,傳遞的參數為一陣列,key值有clientCache、serverCache、info,再結束執行,預設不使用.
316
		$conf["sock::unixDomainSockServer"]["shutdownCallback"]="\qbpwcf\\resource::closeAllResurce";
327 liveuser 317
		#參考資料:
318
		#http://php.net/manual/en/function.stream-socket-server.php
319
		#備註:
320
		#無.
321
		$unixDomainSockServer=sock::unixDomainSockServer($conf["sock::unixDomainSockServer"]);
322
		unset($conf["sock::unixDomainSockServer"]);
323
 
324
		#如果異常
325
		if($unixDomainSockServer["status"]==="false"){
326
 
327
			#設置執行異常
328
			$result["status"]="false";
329
 
330
			#設置執行錯誤訊息
331
			$result["error"]=$unixDomainSockServer;
332
 
333
			#回傳結果
334
			return $result;
335
 
336
			}#if end
337
 
338
		#設置執行正常
339
		$result["status"]="true";
340
 
341
		#回傳結果
342
		return $result;
343
 
344
		}#function server end
306 liveuser 345
 
327 liveuser 346
	/*
347
	#函式說明:
348
	#用於 server 的 addOnProcessFunc,亦即收到用戶訊息要做什麼事情.
349
	#回傳結果:
350
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
351
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
352
	#$result["function"],當前執行的函式名稱.
353
	#必填參數:
354
	#$conf["info"],陣列,資料庫資訊.
355
	$conf["info"]=array();
368 liveuser 356
	#$conf["request"],字串,收到的json訊息,其元素key值有"id":用於識別unix domain client用戶該次訊息的id;"data":array("action","condition","value","type"),"action"的數值有read(讀取資源)跟write(寫入資源);"condition"的數值為一陣列,若為空陣列則代表沒有條件,通常是為新增資源,元素的key為"id"者代表目標資源的id,沒有時不會傳遞該參數;元素的key為"value"者代表目標資源是否相等於"value",且"type"為"php_variable";元素的key為"pid"者代表運行的資源程序pid,且"type"為"proc";"value"為資源,為任意php變數;"type"有php_variable(任何php變數)跟proc(透過指令啟動,透過unix domain socket互動).
327 liveuser 357
	$conf["request"]="";
368 liveuser 358
	#$conf["socket"],object,用戶的socket.
359
	$conf["socket"]=$object;
327 liveuser 360
	#$conf["clientCache"],陣列,給予所有用戶的cache.
361
	$conf["clientCache"]=array();
368 liveuser 362
	#$conf["last_req_time"],字串,收到client要求的時間.
363
	$conf["last_req_time"]="";
327 liveuser 364
	#可省略參數:
365
	#無.
366
	#參考資料:
367
	#無.
368
	#備註:
369
	#無.
370
	*/
371
	public static function addOnProcessFunc(&$conf){
372
 
373
		#初始化要回傳的結果
374
		$result=array();
375
 
376
		#取得當前執行的函數名稱
377
		$result["function"]=__FUNCTION__;
378
 
379
		#如果沒有參數
380
		if(func_num_args()==0){
381
 
306 liveuser 382
			#設置執行失敗
383
			$result["status"]="false";
384
 
385
			#設置執行錯誤訊息
327 liveuser 386
			$result["error"]="函數".$result["function"]."需要參數";
306 liveuser 387
 
388
			#回傳結果
389
			return $result;
390
 
391
			}#if end
392
 
327 liveuser 393
		#涵式說明:
394
		#判斷當前環境為web還是cmd
395
		#回傳結果:
396
		#$result,"web"或"cmd"
397
		if(csInformation::getEnv()==="web"){
398
 
306 liveuser 399
			#設置執行失敗
400
			$result["status"]="false";
401
 
402
			#設置執行錯誤訊息
327 liveuser 403
			$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
306 liveuser 404
 
405
			#回傳結果
406
			return $result;
407
 
408
			}#if end
409
 
327 liveuser 410
		#取得參數
411
		$result["argu"]=$conf;
412
 
413
		#如果 $conf 不為陣列
414
		if(gettype($conf)!=="array"){
415
 
416
			#設置執行失敗
417
			$result["status"]="false";
418
 
419
			#設置執行錯誤訊息
420
			$result["error"][]="\$conf變數須為陣列形態";
421
 
422
			#如果傳入的參數為 null
423
			if(is_null($conf)){
424
 
425
				#設置執行錯誤訊息
426
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
427
 
428
				}#if end
429
 
430
			#回傳結果
431
			return $result;
432
 
433
			}#if end
434
 
435
		#檢查參數
436
		#函式說明:
437
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
438
		#回傳結果:
439
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
440
		#$result["error"],執行不正常結束的錯訊息陣列.
441
		#$result["simpleError"],簡單表示的錯誤訊息.
442
		#$result["function"],當前執行的函式名稱.
443
		#$result["argu"],設置給予的參數.
444
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
445
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
446
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
447
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
448
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
449
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
450
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
451
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
452
		#必填參數:
453
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
454
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
455
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
339 liveuser 456
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
327 liveuser 457
		#可省略參數:
458
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
368 liveuser 459
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("request","socket","clientCache","last_req_time");
327 liveuser 460
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
368 liveuser 461
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","resource","array","integer");
327 liveuser 462
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
463
		#$conf["canBeEmptyString"]="false";
464
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
465
		#$conf["canNotBeEmpty"]=array();
466
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
467
		#$conf["canBeEmpty"]=array();
468
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
368 liveuser 469
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("info");
327 liveuser 470
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
368 liveuser 471
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("info");
327 liveuser 472
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
368 liveuser 473
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
327 liveuser 474
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
475
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($sock);
476
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
477
		#$conf["disallowAllSkipableVarIsEmpty"]="";
478
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
479
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
480
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
481
		#$conf["disallowAllSkipableVarNotExist"]="";
482
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
483
		#$conf["arrayCountEqualCheck"][]=array();
484
		#參考資料:
485
		#array_keys=>http://php.net/manual/en/function.array-keys.php
486
		#備註:
487
		#無.
488
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
489
		unset($conf["variableCheck::checkArguments"]);
490
 
491
		#如果執行異常
492
		if($checkArguments["status"]==="false"){
493
 
494
			#設置執行異常識別
495
			$result["status"]="false";
496
 
497
			#設置執行錯誤
498
			$result["error"]=$checkArguments;
499
 
500
			#回傳結果
501
			return $result;
502
 
503
			}#if end
504
 
505
		#如果檢查不通過
506
		if($checkArguments["passed"]==="false"){
507
 
508
			#設置執行異常識別
509
			$result["status"]="false";
510
 
511
			#設置執行錯誤
512
			$result["error"]=$checkArguments;
513
 
514
			#回傳結果
515
			return $result;
516
 
517
			}#if end
339 liveuser 518
 
519
		#轉換成陣列
520
		$conf["request"]=(array)($conf["request"]);
521
 
327 liveuser 522
		#檢查參數
523
		#函式說明:
524
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
525
		#回傳結果:
526
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
527
		#$result["error"],執行不正常結束的錯訊息陣列.
528
		#$result["simpleError"],簡單表示的錯誤訊息.
529
		#$result["function"],當前執行的函式名稱.
530
		#$result["argu"],設置給予的參數.
531
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
532
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
533
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
534
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
535
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
536
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
537
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
538
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
539
		#必填參數:
540
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
339 liveuser 541
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf["request"];
327 liveuser 542
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
339 liveuser 543
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
327 liveuser 544
		#可省略參數:
545
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
368 liveuser 546
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("data");
547
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
548
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
549
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
550
		#$conf["canBeEmptyString"]="false";
551
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
552
		#$conf["canNotBeEmpty"]=array();
553
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
554
		#$conf["canBeEmpty"]=array();
555
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
556
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("action");
557
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
558
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("condition","value","type");
559
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
560
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array",null,"string");
561
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
562
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array(),null,null);
563
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
564
		#$conf["disallowAllSkipableVarIsEmpty"]="";
565
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
566
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
567
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
568
		#$conf["disallowAllSkipableVarNotExist"]="";
569
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
570
		#$conf["arrayCountEqualCheck"][]=array();
571
		#參考資料:
572
		#array_keys=>http://php.net/manual/en/function.array-keys.php
573
		#備註:
574
		#無.
575
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
576
		unset($conf["variableCheck::checkArguments"]);
577
 
578
		#如果執行異常
579
		if($checkArguments["status"]==="false"){
580
 
581
			#設置執行異常識別
582
			$result["status"]="false";
583
 
584
			#設置執行錯誤
585
			$result["error"]=$checkArguments;
586
 
587
			#回傳結果
588
			return $result;
589
 
590
			}#if end
591
 
592
		#如果檢查不通過
593
		if($checkArguments["passed"]==="false"){
594
 
595
			#設置執行異常識別
596
			$result["status"]="false";
597
 
598
			#設置執行錯誤
599
			$result["error"]=$checkArguments;
600
 
601
			#回傳結果
602
			return $result;
603
 
604
			}#if end
605
 
606
		#檢查參數
607
		#函式說明:
608
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
609
		#回傳結果:
610
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
611
		#$result["error"],執行不正常結束的錯訊息陣列.
612
		#$result["simpleError"],簡單表示的錯誤訊息.
613
		#$result["function"],當前執行的函式名稱.
614
		#$result["argu"],設置給予的參數.
615
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
616
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
617
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
618
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
619
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
620
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
621
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
622
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
623
		#必填參數:
624
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
625
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf["request"]["data"];
626
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
627
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
628
		#可省略參數:
629
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
327 liveuser 630
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("action");
631
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
632
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
633
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
634
		#$conf["canBeEmptyString"]="false";
635
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
636
		#$conf["canNotBeEmpty"]=array();
637
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
638
		#$conf["canBeEmpty"]=array();
639
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
640
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("action");
641
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
642
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("condition","value","type");
643
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
644
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array",null,"string");
645
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
646
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array(),null,null);
647
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
648
		#$conf["disallowAllSkipableVarIsEmpty"]="";
649
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
650
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
651
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
652
		#$conf["disallowAllSkipableVarNotExist"]="";
653
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
654
		#$conf["arrayCountEqualCheck"][]=array();
655
		#參考資料:
656
		#array_keys=>http://php.net/manual/en/function.array-keys.php
657
		#備註:
658
		#無.
659
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
660
		unset($conf["variableCheck::checkArguments"]);
661
 
662
		#如果執行異常
663
		if($checkArguments["status"]==="false"){
664
 
665
			#設置執行異常識別
666
			$result["status"]="false";
667
 
668
			#設置執行錯誤
669
			$result["error"]=$checkArguments;
670
 
671
			#回傳結果
672
			return $result;
673
 
674
			}#if end
675
 
676
		#如果檢查不通過
677
		if($checkArguments["passed"]==="false"){
678
 
679
			#設置執行異常識別
680
			$result["status"]="false";
681
 
682
			#設置執行錯誤
683
			$result["error"]=$checkArguments;
684
 
685
			#回傳結果
686
			return $result;
687
 
688
			}#if end
689
 
368 liveuser 690
		#取得 request data 的參考
691
		$rdata=&$conf["request"]["data"];
692
 
327 liveuser 693
		#判斷 action
368 liveuser 694
		switch($rdata["action"]){
327 liveuser 695
 
696
			#如果是要寫入
697
			case "write":
698
 
699
				#如果是空的,亦即沒有條件
368 liveuser 700
				if(empty($rdata["condition"])){
327 liveuser 701
 
702
					#代表要新增資料
703
 
704
					#判斷類型
368 liveuser 705
					switch($rdata["type"]){
327 liveuser 706
 
707
						#如果是 php 變數
708
						case "php_variable":
709
 
710
							#產生id
711
							#函式說明:
712
							#使用 linux 的 uuid 指令來產生 uuid 字串
713
							#回傳結果:
714
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
715
							#$result["error"],錯誤訊息.
716
							#$result["function"],當前執行的函式名稱.
717
							#$result["content"],uuid.
718
							#必填參數:
719
							#無.
720
							#可省略參數:
721
							#無.
722
							#參考資料:
723
							#無.
724
							#備註:
725
							#無.
726
							$uuid=cmd::uuid();
727
 
728
							#如果執行異常
729
							if($uuid["status"]==="false"){
730
 
731
								#設置執行異常識別
732
								$result["status"]="false";
733
 
734
								#設置執行錯誤
735
								$result["error"]=$uuid;
736
 
737
								#回傳結果
738
								return $result;
739
 
740
								}#if end
741
 
742
							#取得uuid
743
							$uuid=$uuid["content"];
744
 
745
							#初始化要設置的列
746
							$row=array();
747
 
748
							#設置存放的數值
368 liveuser 749
							$row["value"]=$rdata["value"];
327 liveuser 750
 
751
							#設置形態
368 liveuser 752
							$row["type"]=$rdata["type"];
327 liveuser 753
 
339 liveuser 754
							#若無設定 life
368 liveuser 755
							if(!isset($rdata["life"])){
339 liveuser 756
 
757
								#設置預設的life
758
								$row["life"]=time()+$conf["info"]["defaultLifeTime"];
759
 
760
								}#if end
761
 
327 liveuser 762
							#新增資料並指定 id
763
							$conf["info"]["resource"][$uuid]=$row;
764
 
765
							#設置新增的資料
766
							$result["content"]=array("id"=>$uuid,"info"=>$row);
767
 
768
							#設置執行正常
769
							$result["status"]="true";
770
 
771
							#回傳結果
772
							return $result;
773
 
774
							#跳出 switch
775
							break 2;
776
 
777
						#若是 proc
778
						case "proc":
779
 
780
							#取得要運行的程式與參數
368 liveuser 781
							$cmdAndArgu=$rdata["value"];
327 liveuser 782
 
783
							#函式說明:
784
							#透過proc來多執行序運作.
785
							#回傳結果:
786
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
787
							#$reuslt["error"],執行不正常結束的錯訊息陣列.
788
							#$result["function"],當前執行的函式名稱.
789
							#$result["argu"],使用的參數.
790
							#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"content"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
791
							#必填參數:
792
							#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
793
							$conf["threads::proc"]["cmds"]=array($cmdAndArgu);
794
							#可省略參數:
795
							#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
796
							$conf["threads::proc"]["wait"]="false";
797
							#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
798
							#$conf["timeout"]=array("10");
799
							#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
800
							#$conf["workingDir"]=array("path");
801
							#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
802
							#$conf["envs"]=array(array("key"=>"value"));
803
							#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
804
							#$conf["executeBy"]=array("bash");
805
							#參考資料:
806
							#https://www.php.net/manual/en/function.proc-open.php
807
							#https://www.php.net/manual/en/function.proc-get-status.php
808
							#https://www.php.net/manual/en/function.proc-terminate.php
809
							#備註:
810
							#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
811
							#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
812
							$proc=threads::proc($conf["threads::proc"]);
813
							unset($conf["threads::proc"]);
814
 
815
							#如果執行異常
816
							if($proc["status"]==="false"){
817
 
818
								#設置跳過,不適用
819
								$result["status"]="continue";
820
 
821
								#回傳結果
822
								return $result;
823
 
824
								}#if end
825
 
826
							#函式說明:
827
							#更新透過proc執行的多程序資訊.
828
							#回傳結果:
829
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
830
							#$reuslt["error"],執行不正常結束的錯訊息陣列.
831
							#$result["function"],當前執行的函式名稱.
832
							#$result["argu"],使用的參數.
833
							#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
834
							#必填參數:
835
							#$conf["procs"],陣列,運行self::proc後回傳的content.
836
							$conf["threads::proc_update"]["procs"]=$procs["content"];
837
							#可省略參數:
838
							#無.
839
							#參考資料:
840
							#無.
841
							#備註:
842
							#無.
843
							$proc_update=threads::proc_update($conf["threads::proc_update"]);
844
							unset($conf["threads::proc_update"]);
845
 
846
							#如果執行異常
847
							if($proc_update["status"]==="false"){
848
 
849
								#設置跳過,不適用
850
								$result["status"]="continue";
851
 
852
								#回傳結果
853
								return $result;
854
 
855
								}#if end
856
 
857
							#如果proc裡面的程式執行異常
858
							if($proc_update["content"]["status"]==="false"){
859
 
860
								#設置跳過,不適用
861
								$result["status"]="continue";
862
 
863
								#回傳結果
864
								return $result;
865
 
866
								}#if end
867
 
868
							#取得要儲存的php變數
339 liveuser 869
							$value=$proc_update["content"][0];
327 liveuser 870
 
871
							#產生id
872
							#函式說明:
873
							#使用 linux 的 uuid 指令來產生 uuid 字串
874
							#回傳結果:
875
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
876
							#$result["error"],錯誤訊息.
877
							#$result["function"],當前執行的函式名稱.
878
							#$result["content"],uuid.
879
							#必填參數:
880
							#無.
881
							#可省略參數:
882
							#無.
883
							#參考資料:
884
							#無.
885
							#備註:
886
							#無.
887
							$uuid=cmd::uuid();
888
 
889
							#如果執行異常
890
							if($uuid["status"]==="false"){
891
 
892
								#設置執行異常識別
893
								$result["status"]="false";
894
 
895
								#設置執行錯誤
896
								$result["error"]=$uuid;
897
 
898
								#回傳結果
899
								return $result;
900
 
901
								}#if end
902
 
903
							#取得uuid
904
							$uuid=$uuid["content"];
905
 
906
							#初始化要設置的列
907
							$row=array();
908
 
909
							#設置存放的數值
910
							$row["value"]=$value;
911
 
912
							#設置形態
368 liveuser 913
							$row["type"]=$rdata["type"];
327 liveuser 914
 
915
							#新增資料並指定 id
916
							$conf["info"]["resource"][$uuid]=$row;
917
 
339 liveuser 918
							#若無設定 life
368 liveuser 919
							if(!isset($rdata["life"])){
339 liveuser 920
 
921
								#設置預設的life
922
								$row["life"]=time()+$conf["info"]["defaultLifeTime"];
923
 
924
								}#if end
925
 
327 liveuser 926
							#設置新增的資料
927
							$result["content"]=array("id"=>$uuid,"info"=>$row);
928
 
929
							#設置執行正常
930
							$result["status"]="true";
931
 
932
							#回傳結果
933
							return $result;
934
 
935
							#跳出 switch
936
							break 2;
937
 
938
						#其他類型
939
						default: 
940
 
941
							#設置錯誤訊息
368 liveuser 942
							$result["error"][]="unsupported type:".$rdata["type"];
327 liveuser 943
 
944
							#設置執行異常
945
							$result["status"]="false";
946
 
947
							#回傳結果
948
							return $result;
949
 
950
						}#switch end
951
 
952
					}#if end
953
 
954
				#反之有條件
955
				else{
956
 
957
					#針對每個條件
368 liveuser 958
					foreach($rdata["condition"] as $key => $val){
327 liveuser 959
 
960
						#判斷 $key
961
						switch($key){
962
 
963
							#如果條件欄位是 id
964
							case "id":
965
 
966
								#針對每筆記錄
967
								foreach($conf["info"]["resource"] as $idInM => $valInM){
968
 
969
									#如果找到符合id的資料
970
									if($idInM===$val){
971
 
339 liveuser 972
										#取得現有資源類型
973
										$currentType=$conf["info"]["resource"][$idInM]["type"];
974
 
975
										#如果沒有指定新 type
368 liveuser 976
										if(!isset($rdata["type"])){
339 liveuser 977
 
978
											#視為跟現有資源類型一樣
368 liveuser 979
											$rdata["type"]=$currentType;
339 liveuser 980
 
981
											}#if end
982
 
983
										#判斷新資源類型
368 liveuser 984
										switch($rdata["type"]){
339 liveuser 985
 
986
											#如果為 "php_variable"
987
											case "php_variable":
988
 
989
												#如果既有資源的類型為 "proc"
990
												if($currentType==="proc"){
991
 
992
													#pid
993
													#$valInM["proc_get_status"]["pid"];
994
 
995
													#關閉程序
996
													proc_close($valInM["process"]);
997
 
998
													}#if end
999
 
1000
												#初始化要設置的列
1001
												$row=array();
1002
 
1003
												#設置存放的數值
368 liveuser 1004
												$row["value"]=$rdata["value"];
339 liveuser 1005
 
1006
												#設置形態
368 liveuser 1007
												$row["type"]=$rdata["type"];
339 liveuser 1008
 
1009
												#若無設定 life
368 liveuser 1010
												if(!isset($rdata["life"])){
339 liveuser 1011
 
1012
													#設置預設的life
1013
													$row["life"]=time()+$conf["info"]["defaultLifeTime"];
1014
 
1015
													}#if end
1016
 
1017
												#寫入資源
1018
												$conf["info"]["resource"][$idInM]=$row;
1019
 
1020
												#跳出 switch
1021
												break;
1022
 
1023
											#如果為 "proc"
1024
											case "proc":
1025
 
1026
												#如果既有資源的類型為 "proc"
1027
												if($currentType==="proc"){
1028
 
1029
													#pid
1030
													#$valInM["proc_get_status"]["pid"];
1031
 
1032
													#關閉程序
1033
													proc_close($valInM["process"]);
1034
 
1035
													}#if end
1036
 
1037
												#取得要運行的程式與參數
368 liveuser 1038
												$cmdAndArgu=$rdata["value"];
339 liveuser 1039
 
1040
												#函式說明:
1041
												#透過proc來多執行序運作.
1042
												#回傳結果:
1043
												#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1044
												#$reuslt["error"],執行不正常結束的錯訊息陣列.
1045
												#$result["function"],當前執行的函式名稱.
1046
												#$result["argu"],使用的參數.
1047
												#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"content"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
1048
												#必填參數:
1049
												#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
1050
												$conf["threads::proc"]["cmds"]=array($cmdAndArgu);
1051
												#可省略參數:
1052
												#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
1053
												$conf["threads::proc"]["wait"]="false";
1054
												#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
1055
												#$conf["timeout"]=array("10");
1056
												#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
1057
												#$conf["workingDir"]=array("path");
1058
												#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
1059
												#$conf["envs"]=array(array("key"=>"value"));
1060
												#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
1061
												#$conf["executeBy"]=array("bash");
1062
												#參考資料:
1063
												#https://www.php.net/manual/en/function.proc-open.php
1064
												#https://www.php.net/manual/en/function.proc-get-status.php
1065
												#https://www.php.net/manual/en/function.proc-terminate.php
1066
												#備註:
1067
												#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
1068
												#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
1069
												$proc=threads::proc($conf["threads::proc"]);
1070
												unset($conf["threads::proc"]);
1071
 
1072
												#如果執行異常
1073
												if($proc["status"]==="false"){
1074
 
1075
													#設置跳過,不適用
1076
													$result["status"]="continue";
1077
 
1078
													#回傳結果
1079
													return $result;
1080
 
1081
													}#if end
1082
 
1083
												#函式說明:
1084
												#更新透過proc執行的多程序資訊.
1085
												#回傳結果:
1086
												#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1087
												#$reuslt["error"],執行不正常結束的錯訊息陣列.
1088
												#$result["function"],當前執行的函式名稱.
1089
												#$result["argu"],使用的參數.
1090
												#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
1091
												#必填參數:
1092
												#$conf["procs"],陣列,運行self::proc後回傳的content.
1093
												$conf["threads::proc_update"]["procs"]=$procs["content"];
1094
												#可省略參數:
1095
												#無.
1096
												#參考資料:
1097
												#無.
1098
												#備註:
1099
												#無.
1100
												$proc_update=threads::proc_update($conf["threads::proc_update"]);
1101
												unset($conf["threads::proc_update"]);
1102
 
1103
												#如果執行異常
1104
												if($proc_update["status"]==="false"){
1105
 
1106
													#設置跳過,不適用
1107
													$result["status"]="continue";
1108
 
1109
													#回傳結果
1110
													return $result;
1111
 
1112
													}#if end
1113
 
1114
												#如果proc裡面的程式執行異常
1115
												if($proc_update["content"]["status"]==="false"){
1116
 
1117
													#設置跳過,不適用
1118
													$result["status"]="continue";
1119
 
1120
													#回傳結果
1121
													return $result;
1122
 
1123
													}#if end
1124
 
1125
												#取得要儲存的php變數
1126
												$value=$proc_update["content"][0];
1127
 
1128
												#初始化要設置的列
1129
												$row=array();
1130
 
1131
												#設置存放的數值
1132
												$row["value"]=$value;
1133
 
1134
												#設置形態
368 liveuser 1135
												$row["type"]=$rdata["type"];
339 liveuser 1136
 
1137
												#若無設定 life
368 liveuser 1138
												if(!isset($rdata["life"])){
339 liveuser 1139
 
1140
													#設置預設的life
1141
													$row["life"]=time()+$conf["info"]["defaultLifeTime"];
1142
 
1143
													}#if end
1144
 
1145
												#寫入資源
1146
												$conf["info"]["resource"][$idInM]=$row;
1147
 
1148
												#跳出 switch
1149
												break;
1150
 
1151
											#其他 type
1152
											default:
1153
 
1154
												#設置錯誤訊息
368 liveuser 1155
												$result["error"][]="unsupported type:".$rdata["type"];
339 liveuser 1156
 
1157
												#設置執行異常
1158
												$result["status"]="false";
1159
 
1160
												#回傳結果
1161
												return $result;
1162
 
1163
											}#switch end
1164
 
327 liveuser 1165
										#設置結果
339 liveuser 1166
										$result["content"]=array("id"=>$idInM,"value"=>$conf["info"]["resource"][$valInM]);
327 liveuser 1167
 
1168
										#設置執行正常
1169
										$result["status"]="true";
1170
 
1171
										#回傳結果
1172
										return $result;
1173
 
1174
										}#if end
1175
 
1176
									}#foreach end
1177
 
1178
								#執行到這邊代表沒有符合條件的記錄
1179
 
1180
								#設置結果為null
1181
								$result["content"]=null;
1182
 
1183
								#設置執行正常
1184
								$result["status"]="true";
1185
 
1186
								#回傳結果
1187
								return $result;
1188
 
1189
								#跳出 switch
1190
								break;
1191
 
1192
							#如果條件欄位是 value
1193
							case "value":
1194
 
339 liveuser 1195
								#針對每筆記錄
327 liveuser 1196
								foreach($conf["info"]["resource"] as $idInM => $valInM){
1197
 
1198
									#如果不是 php_variable
1199
									if($valInM["type"]!=="php_variable"){
1200
 
1201
										#跳過之
1202
										continue;
1203
 
1204
										}#if end
1205
 
1206
									#如果找到符合value的資料
1207
									if($valInM===$val){
1208
 
339 liveuser 1209
										#如果沒有指定新 type
368 liveuser 1210
										if(!isset($rdata["type"])){
327 liveuser 1211
 
339 liveuser 1212
											#視為跟現有資源類型一樣
368 liveuser 1213
											$rdata["type"]=$currentType;
327 liveuser 1214
 
339 liveuser 1215
											}#if end
327 liveuser 1216
 
339 liveuser 1217
										#判斷新資源類型
368 liveuser 1218
										switch($rdata["type"]){
339 liveuser 1219
 
1220
											#如果為 "php_variable"
1221
											case "php_variable":
1222
 
1223
												#如果既有資源的類型為 "proc"
1224
												if($currentType==="proc"){
1225
 
1226
													#pid
1227
													#$valInM["proc_get_status"]["pid"];
1228
 
1229
													#關閉程序
1230
													proc_close($valInM["process"]);
1231
 
1232
													}#if end
1233
 
1234
												#初始化要設置的列
1235
												$row=array();
1236
 
1237
												#設置存放的數值
368 liveuser 1238
												$row["value"]=$rdata["value"];
339 liveuser 1239
 
1240
												#設置形態
368 liveuser 1241
												$row["type"]=$rdata["type"];
339 liveuser 1242
 
1243
												#若無設定 life
368 liveuser 1244
												if(!isset($rdata["life"])){
339 liveuser 1245
 
1246
													#設置預設的life
1247
													$row["life"]=time()+$conf["info"]["defaultLifeTime"];
1248
 
1249
													}#if end
1250
 
1251
												#寫入資源
1252
												$conf["info"]["resource"][$idInM]=$row;
1253
 
1254
												#跳出 switch
1255
												break;
1256
 
1257
											#如果為 "proc"
1258
											case "proc":
1259
 
1260
												#如果既有資源的類型為 "proc"
1261
												if($currentType==="proc"){
1262
 
1263
													#pid
1264
													#$valInM["proc_get_status"]["pid"];
1265
 
1266
													#關閉程序
1267
													proc_close($valInM["process"]);
1268
 
1269
													}#if end
1270
 
1271
												#取得要運行的程式與參數
368 liveuser 1272
												$cmdAndArgu=$rdata["value"];
339 liveuser 1273
 
1274
												#函式說明:
1275
												#透過proc來多執行序運作.
1276
												#回傳結果:
1277
												#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1278
												#$reuslt["error"],執行不正常結束的錯訊息陣列.
1279
												#$result["function"],當前執行的函式名稱.
1280
												#$result["argu"],使用的參數.
1281
												#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"content"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
1282
												#必填參數:
1283
												#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
1284
												$conf["threads::proc"]["cmds"]=array($cmdAndArgu);
1285
												#可省略參數:
1286
												#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
1287
												$conf["threads::proc"]["wait"]="false";
1288
												#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
1289
												#$conf["timeout"]=array("10");
1290
												#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
1291
												#$conf["workingDir"]=array("path");
1292
												#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
1293
												#$conf["envs"]=array(array("key"=>"value"));
1294
												#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
1295
												#$conf["executeBy"]=array("bash");
1296
												#參考資料:
1297
												#https://www.php.net/manual/en/function.proc-open.php
1298
												#https://www.php.net/manual/en/function.proc-get-status.php
1299
												#https://www.php.net/manual/en/function.proc-terminate.php
1300
												#備註:
1301
												#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
1302
												#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
1303
												$proc=threads::proc($conf["threads::proc"]);
1304
												unset($conf["threads::proc"]);
1305
 
1306
												#如果執行異常
1307
												if($proc["status"]==="false"){
1308
 
1309
													#設置跳過,不適用
1310
													$result["status"]="continue";
1311
 
1312
													#回傳結果
1313
													return $result;
1314
 
1315
													}#if end
1316
 
1317
												#函式說明:
1318
												#更新透過proc執行的多程序資訊.
1319
												#回傳結果:
1320
												#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1321
												#$reuslt["error"],執行不正常結束的錯訊息陣列.
1322
												#$result["function"],當前執行的函式名稱.
1323
												#$result["argu"],使用的參數.
1324
												#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
1325
												#必填參數:
1326
												#$conf["procs"],陣列,運行self::proc後回傳的content.
1327
												$conf["threads::proc_update"]["procs"]=$procs["content"];
1328
												#可省略參數:
1329
												#無.
1330
												#參考資料:
1331
												#無.
1332
												#備註:
1333
												#無.
1334
												$proc_update=threads::proc_update($conf["threads::proc_update"]);
1335
												unset($conf["threads::proc_update"]);
1336
 
1337
												#如果執行異常
1338
												if($proc_update["status"]==="false"){
1339
 
1340
													#設置跳過,不適用
1341
													$result["status"]="continue";
1342
 
1343
													#回傳結果
1344
													return $result;
1345
 
1346
													}#if end
1347
 
1348
												#如果proc裡面的程式執行異常
1349
												if($proc_update["content"]["status"]==="false"){
1350
 
1351
													#設置跳過,不適用
1352
													$result["status"]="continue";
1353
 
1354
													#回傳結果
1355
													return $result;
1356
 
1357
													}#if end
1358
 
1359
												#取得要儲存的php變數
1360
												$value=$proc_update["content"][0];
1361
 
1362
												#初始化要設置的列
1363
												$row=array();
1364
 
1365
												#設置存放的數值
1366
												$row["value"]=$value;
1367
 
1368
												#設置形態
368 liveuser 1369
												$row["type"]=$rdata["type"];
339 liveuser 1370
 
1371
												#若無設定 life
368 liveuser 1372
												if(!isset($rdata["life"])){
339 liveuser 1373
 
1374
													#設置預設的life
1375
													$row["life"]=time()+$conf["info"]["defaultLifeTime"];
1376
 
1377
													}#if end
1378
 
1379
												#寫入資源
1380
												$conf["info"]["resource"][$idInM]=$row;
1381
 
1382
												#跳出 switch
1383
												break;
1384
 
1385
											#其他 type
1386
											default:
1387
 
1388
												#設置錯誤訊息
368 liveuser 1389
												$result["error"][]="unsupported type:".$rdata["type"];
339 liveuser 1390
 
1391
												#設置執行異常
1392
												$result["status"]="false";
1393
 
1394
												#回傳結果
1395
												return $result;
1396
 
1397
											}#switch end
1398
 
327 liveuser 1399
										}#if end
1400
 
1401
									}#foreach end
1402
 
1403
								#執行到這邊代表沒有符合條件的記錄
1404
 
1405
								#設置結果為null
1406
								$result["content"]=null;
1407
 
1408
								#設置執行正常
1409
								$result["status"]="true";
1410
 
1411
								#回傳結果
1412
								return $result;
1413
 
1414
								#跳出 switch
1415
								break;
1416
 
1417
							#如果條件欄位是 pid
1418
							case "pid":
1419
 
339 liveuser 1420
								#針對每筆記錄
368 liveuser 1421
								foreach($rdata["resource"] as $idInM => $valInM){
327 liveuser 1422
 
1423
									#如果不是 proc
1424
									if($valInM["type"]!=="proc"){
1425
 
1426
										#跳過之
1427
										continue;
1428
 
1429
										}#if end
1430
 
1431
									#取得 proc 的 pid
339 liveuser 1432
									$pidInM=$valInM["proc_get_status"]["pid"];
327 liveuser 1433
 
1434
									#如果找到符合value的資料
1435
									if($pidInM===$val){
1436
 
339 liveuser 1437
										#如果沒有指定新 type
368 liveuser 1438
										if(!isset($rdata["type"])){
327 liveuser 1439
 
339 liveuser 1440
											#視為跟現有資源類型一樣
368 liveuser 1441
											$rdata["type"]=$currentType;
327 liveuser 1442
 
339 liveuser 1443
											}#if end
327 liveuser 1444
 
339 liveuser 1445
										#判斷新資源類型
368 liveuser 1446
										switch($rdata["type"]){
339 liveuser 1447
 
1448
											#如果為 "php_variable"
1449
											case "php_variable":
1450
 
1451
												#如果既有資源的類型為 "proc"
1452
												if($currentType==="proc"){
1453
 
1454
													#pid
1455
													#$valInM["proc_get_status"]["pid"];
1456
 
1457
													#關閉程序
1458
													proc_close($valInM["process"]);
1459
 
1460
													}#if end
1461
 
1462
												#初始化要設置的列
1463
												$row=array();
1464
 
1465
												#設置存放的數值
368 liveuser 1466
												$row["value"]=$rdata["value"];
339 liveuser 1467
 
1468
												#設置形態
368 liveuser 1469
												$row["type"]=rdata["request"]["type"];
339 liveuser 1470
 
1471
												#若無設定 life
368 liveuser 1472
												if(!isset($rdata["life"])){
339 liveuser 1473
 
1474
													#設置預設的life
1475
													$row["life"]=time()+$conf["info"]["defaultLifeTime"];
1476
 
1477
													}#if end
1478
 
1479
												#寫入資源
1480
												$conf["info"]["resource"][$idInM]=$row;
1481
 
1482
												#跳出 switch
1483
												break;
1484
 
1485
											#如果為 "proc"
1486
											case "proc":
1487
 
1488
												#如果既有資源的類型為 "proc"
1489
												if($currentType==="proc"){
1490
 
1491
													#pid
1492
													#$valInM["proc_get_status"]["pid"];
1493
 
1494
													#關閉程序
1495
													proc_close($valInM["process"]);
1496
 
1497
													}#if end
1498
 
1499
												#取得要運行的程式與參數
368 liveuser 1500
												$cmdAndArgu=$rdata["value"];
339 liveuser 1501
 
1502
												#函式說明:
1503
												#透過proc來多執行序運作.
1504
												#回傳結果:
1505
												#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1506
												#$reuslt["error"],執行不正常結束的錯訊息陣列.
1507
												#$result["function"],當前執行的函式名稱.
1508
												#$result["argu"],使用的參數.
1509
												#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"content"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
1510
												#必填參數:
1511
												#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
1512
												$conf["threads::proc"]["cmds"]=array($cmdAndArgu);
1513
												#可省略參數:
1514
												#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
1515
												$conf["threads::proc"]["wait"]="false";
1516
												#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
1517
												#$conf["timeout"]=array("10");
1518
												#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
1519
												#$conf["workingDir"]=array("path");
1520
												#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
1521
												#$conf["envs"]=array(array("key"=>"value"));
1522
												#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
1523
												#$conf["executeBy"]=array("bash");
1524
												#參考資料:
1525
												#https://www.php.net/manual/en/function.proc-open.php
1526
												#https://www.php.net/manual/en/function.proc-get-status.php
1527
												#https://www.php.net/manual/en/function.proc-terminate.php
1528
												#備註:
1529
												#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
1530
												#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
1531
												$proc=threads::proc($conf["threads::proc"]);
1532
												unset($conf["threads::proc"]);
1533
 
1534
												#如果執行異常
1535
												if($proc["status"]==="false"){
1536
 
1537
													#設置跳過,不適用
1538
													$result["status"]="continue";
1539
 
1540
													#回傳結果
1541
													return $result;
1542
 
1543
													}#if end
1544
 
1545
												#函式說明:
1546
												#更新透過proc執行的多程序資訊.
1547
												#回傳結果:
1548
												#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1549
												#$reuslt["error"],執行不正常結束的錯訊息陣列.
1550
												#$result["function"],當前執行的函式名稱.
1551
												#$result["argu"],使用的參數.
1552
												#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
1553
												#必填參數:
1554
												#$conf["procs"],陣列,運行self::proc後回傳的content.
1555
												$conf["threads::proc_update"]["procs"]=$procs["content"];
1556
												#可省略參數:
1557
												#無.
1558
												#參考資料:
1559
												#無.
1560
												#備註:
1561
												#無.
1562
												$proc_update=threads::proc_update($conf["threads::proc_update"]);
1563
												unset($conf["threads::proc_update"]);
1564
 
1565
												#如果執行異常
1566
												if($proc_update["status"]==="false"){
1567
 
1568
													#設置跳過,不適用
1569
													$result["status"]="continue";
1570
 
1571
													#回傳結果
1572
													return $result;
1573
 
1574
													}#if end
1575
 
1576
												#如果proc裡面的程式執行異常
1577
												if($proc_update["content"][0]["status"]==="false"){
1578
 
1579
													#設置跳過,不適用
1580
													$result["status"]="continue";
1581
 
1582
													#回傳結果
1583
													return $result;
1584
 
1585
													}#if end
1586
 
1587
												#取得要儲存的php變數
1588
												$value=$proc_update["content"][0];
1589
 
1590
												#初始化要設置的列
1591
												$row=array();
1592
 
1593
												#設置存放的數值
1594
												$row["value"]=$value;
1595
 
1596
												#設置形態
368 liveuser 1597
												$row["type"]=$rdata["type"];
339 liveuser 1598
 
1599
												#若無設定 life
368 liveuser 1600
												if(!isset($rdata["life"])){
339 liveuser 1601
 
1602
													#設置預設的life
1603
													$row["life"]=time()+$conf["info"]["defaultLifeTime"];
1604
 
1605
													}#if end
1606
 
1607
												#寫入資源
1608
												$conf["info"]["resource"][$idInM]=$row;
1609
 
1610
												#跳出 switch
1611
												break;
1612
 
1613
											#其他 type
1614
											default:
1615
 
1616
												#設置錯誤訊息
368 liveuser 1617
												$result["error"][]="unsupported type:".$rdata["type"];
339 liveuser 1618
 
1619
												#設置執行異常
1620
												$result["status"]="false";
1621
 
1622
												#回傳結果
1623
												return $result;
1624
 
1625
											}#switch end
1626
 
327 liveuser 1627
										}#if end
1628
 
1629
									}#foreach end
1630
 
1631
								#執行到這邊代表沒有符合條件的記錄
1632
 
1633
								#設置結果為null
1634
								$result["content"]=null;
1635
 
1636
								#設置執行正常
1637
								$result["status"]="true";
1638
 
1639
								#回傳結果
1640
								return $result;
1641
 
1642
								#跳出 switch
1643
								break;
1644
 
1645
							#其他欄位
1646
							default:
1647
 
1648
								#設置錯誤訊息
1649
								$result["error"][]="unsupported column:".$key;
1650
 
1651
								#設置執行異常
1652
								$result["status"]="false";
1653
 
1654
								#回傳結果
1655
								return $result;
1656
 
1657
							}#switch end
339 liveuser 1658
 
327 liveuser 1659
						}#foreach end
1660
 
1661
					}#else end
1662
 
1663
				#結束switch
1664
				break;
1665
 
1666
			#如果是 read
1667
			case "read":
1668
 
1669
				#如果是空的,亦即沒有條件,代表要取得全部.
368 liveuser 1670
				if(empty($rdata["condition"])){
327 liveuser 1671
 
1672
					#針對每筆記錄
1673
					foreach($conf["info"]["resource"] as $idInM => $valInM){
1674
 
1675
						#設置要取得的內容
339 liveuser 1676
						$result["content"][]=array("id"=>$idInM,"value"=>$valInM);
327 liveuser 1677
 
1678
						}#foreach end
1679
 
1680
					#設置執行正常
1681
					$result["status"]="true";
1682
 
1683
					#回傳結果
1684
					return $result;
1685
 
1686
					}#if end
1687
 
1688
				#反之有條件
1689
				else{
1690
 
1691
					#針對每個條件
368 liveuser 1692
					foreach($rdata["condition"] as $key => $val){
327 liveuser 1693
 
1694
						#判斷 $key
1695
						switch($key){
1696
 
1697
							#如果條件欄位是 id
1698
							case "id":
1699
 
1700
								#針對每筆記錄
1701
								foreach($conf["info"]["resource"] as $idInM => $valInM){
1702
 
1703
									#如果找到符合id的資料
1704
									if($idInM===$val){
1705
 
1706
										#設置結果
339 liveuser 1707
										$result["content"][]=array("id"=>$idInM,"value"=>$valInM);
327 liveuser 1708
 
1709
										#設置執行正常
1710
										$result["status"]="true";
1711
 
1712
										#回傳結果
1713
										return $result;
1714
 
1715
										}#if end
1716
 
1717
									}#foreach end
1718
 
1719
								#執行到這邊代表沒有符合條件的記錄
1720
 
1721
								#設置結果為null
1722
								$result["content"]=null;
1723
 
1724
								#設置執行正常
1725
								$result["status"]="true";
1726
 
1727
								#回傳結果
1728
								return $result;
1729
 
1730
								#跳出 switch
1731
								break;
1732
 
1733
							#如果條件欄位是 value
1734
							case "value":
1735
 
339 liveuser 1736
								#針對每筆記錄
327 liveuser 1737
								foreach($conf["info"]["resource"] as $idInM => $valInM){
1738
 
1739
									#如果不是 php_variable
1740
									if($valInM["type"]!=="php_variable"){
1741
 
1742
										#跳過之
1743
										continue;
1744
 
1745
										}#if end
1746
 
1747
									#如果找到符合value的資料
1748
									if($valInM===$val){
1749
 
1750
										#設置結果
339 liveuser 1751
										$result["content"]=array("id"=>$idInM,"value"=>$valInM);
327 liveuser 1752
 
1753
										#設置執行結果
1754
										$result["status"]="true";
1755
 
1756
										#回傳結果
1757
										return $result;
1758
 
1759
										}#if end
1760
 
1761
									}#foreach end
1762
 
1763
								#執行到這邊代表沒有符合條件的記錄
1764
 
1765
								#設置結果為null
1766
								$result["content"]=null;
1767
 
1768
								#設置執行正常
1769
								$result["status"]="true";
1770
 
1771
								#回傳結果
1772
								return $result;
1773
 
1774
								#跳出 switch
1775
								break;
1776
 
1777
							#如果條件欄位是 pid
1778
							case "pid":
1779
 
339 liveuser 1780
								#針對每筆記錄
327 liveuser 1781
								foreach($conf["info"]["resource"] as $idInM => $valInM){
1782
 
1783
									#如果不是 proc
1784
									if($valInM["type"]!=="proc"){
1785
 
1786
										#跳過之
1787
										continue;
1788
 
1789
										}#if end
1790
 
1791
									#取得 proc 的 pid
339 liveuser 1792
									$pidInM=$valInM["proc_get_status"]["pid"];
327 liveuser 1793
 
1794
									#如果找到符合value的資料
1795
									if($pidInM===$val){
1796
 
1797
										#設置結果
339 liveuser 1798
										$result["content"]=array("id"=>$idInM,"value"=>$valInM);
327 liveuser 1799
 
1800
										#設置執行結果
1801
										$result["status"]="true";
1802
 
1803
										#回傳結果
1804
										return $result;
1805
 
1806
										}#if end
1807
 
1808
									}#foreach end
1809
 
1810
								#執行到這邊代表沒有符合條件的記錄
1811
 
1812
								#設置結果為null
1813
								$result["content"]=null;
1814
 
1815
								#設置執行正常
1816
								$result["status"]="true";
1817
 
1818
								#回傳結果
1819
								return $result;
1820
 
1821
								#跳出 switch
1822
								break;
1823
 
1824
							#其他欄位
1825
							default:
1826
 
1827
								#設置錯誤訊息
1828
								$result["error"][]="unsupported column:".$key;
1829
 
1830
								#設置執行異常
1831
								$result["status"]="false";
1832
 
1833
								#回傳結果
1834
								return $result;
1835
 
1836
							}#switch end
1837
 
1838
						}#foreach end
1839
 
1840
					}#else end
1841
 
1842
				#結束switch
1843
				break;
1844
 
1845
			#其他 action
1846
			default:
1847
 
1848
				#設置錯誤訊息
1849
				$result["error"][]="unsupported action:".$conf["request"]["action"];
1850
 
1851
				#設置執行異常
1852
				$result["status"]="false";
1853
 
1854
				#回傳結果
1855
				return $result;
1856
 
1857
			}#switch end
1858
 
1859
		#執行到這邊代表不適用
1860
 
1861
		#設置不適用,可跳過
1862
		$result["status"]="continue";
306 liveuser 1863
 
327 liveuser 1864
		#回傳結果
1865
		return $result;
1866
 
1867
		}#function addOnProcessFunc end
306 liveuser 1868
 
327 liveuser 1869
	/*
1870
	#函式說明:
1871
	#用於 server 的 funcToRunWhenIdle,亦即沒有收到訊息閒置時要做什麼事情.
1872
	#回傳結果:
1873
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1874
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
1875
	#$result["function"],當前執行的函式名稱.
1876
	#必填參數:
1877
	#$conf["info"],陣列,資料庫資訊.
1878
	$conf["info"]=array();
339 liveuser 1879
	#$conf["client"],陣列,每個用戶的socket.
1880
	$conf["client"]="";
1881
	#$conf["serverCache"],陣列,只有server可以看到的cache.
1882
	$conf["serverCache"]=array();
327 liveuser 1883
	#$conf["clientCache"],陣列,給予所有用戶的cache.
1884
	$conf["clientCache"]=array();
1885
	#可省略參數:
1886
	#無.
1887
	#參考資料:
1888
	#無.
1889
	#備註:
1890
	#無.
1891
	*/
1892
	public static function funcToRunWhenIdle(&$conf){
1893
 
339 liveuser 1894
		#初始化要回傳的結果
1895
		$result=array();
1896
 
1897
		#取得當前執行的函數名稱
1898
		$result["function"]=__FUNCTION__;
1899
 
1900
		#如果沒有參數
1901
		if(func_num_args()==0){
1902
 
1903
			#設置執行失敗
1904
			$result["status"]="false";
1905
 
1906
			#設置執行錯誤訊息
1907
			$result["error"]="函數".$result["function"]."需要參數";
1908
 
1909
			#回傳結果
1910
			return $result;
1911
 
1912
			}#if end
1913
 
1914
		#涵式說明:
1915
		#判斷當前環境為web還是cmd
1916
		#回傳結果:
1917
		#$result,"web"或"cmd"
1918
		if(csInformation::getEnv()==="web"){
1919
 
1920
			#設置執行失敗
1921
			$result["status"]="false";
1922
 
1923
			#設置執行錯誤訊息
1924
			$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
1925
 
1926
			#回傳結果
1927
			return $result;
1928
 
1929
			}#if end
327 liveuser 1930
 
339 liveuser 1931
		#取得參數
1932
		$result["argu"]=$conf;
1933
 
1934
		#如果 $conf 不為陣列
1935
		if(gettype($conf)!=="array"){
1936
 
1937
			#設置執行失敗
1938
			$result["status"]="false";
1939
 
1940
			#設置執行錯誤訊息
1941
			$result["error"][]="\$conf變數須為陣列形態";
1942
 
1943
			#如果傳入的參數為 null
1944
			if(is_null($conf)){
1945
 
1946
				#設置執行錯誤訊息
1947
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1948
 
1949
				}#if end
1950
 
1951
			#回傳結果
1952
			return $result;
1953
 
1954
			}#if end
1955
 
1956
		#檢查參數
1957
		#函式說明:
1958
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
1959
		#回傳結果:
1960
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1961
		#$result["error"],執行不正常結束的錯訊息陣列.
1962
		#$result["simpleError"],簡單表示的錯誤訊息.
1963
		#$result["function"],當前執行的函式名稱.
1964
		#$result["argu"],設置給予的參數.
1965
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1966
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1967
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1968
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1969
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1970
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1971
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1972
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1973
		#必填參數:
1974
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1975
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1976
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1977
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1978
		#可省略參數:
1979
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1980
		#$conf["mustBeFilledVariableName"]=array();
1981
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
1982
		#$conf["mustBeFilledVariableType"]=array();
1983
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1984
		#$conf["canBeEmptyString"]="false";
1985
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
1986
		#$conf["canNotBeEmpty"]=array();
1987
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
1988
		#$conf["canBeEmpty"]=array();
1989
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
340 liveuser 1990
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("info","serverCache","clientCache");
339 liveuser 1991
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1992
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("info","client","serverCache","clientCache");
1993
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
1994
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("info","client","serverCache","clientCache");
1995
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1996
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($sock);
1997
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
1998
		#$conf["disallowAllSkipableVarIsEmpty"]="";
1999
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
2000
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
2001
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
2002
		#$conf["disallowAllSkipableVarNotExist"]="";
2003
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2004
		#$conf["arrayCountEqualCheck"][]=array();
2005
		#參考資料:
2006
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2007
		#備註:
2008
		#無.
2009
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2010
		unset($conf["variableCheck::checkArguments"]);
2011
 
2012
		#如果執行異常
2013
		if($checkArguments["status"]==="false"){
2014
 
2015
			#設置執行異常識別
2016
			$result["status"]="false";
2017
 
2018
			#設置執行錯誤
2019
			$result["error"]=$checkArguments;
2020
 
2021
			#回傳結果
2022
			return $result;
2023
 
2024
			}#if end
2025
 
2026
		#如果檢查不通過
2027
		if($checkArguments["passed"]==="false"){
2028
 
2029
			#設置執行異常識別
2030
			$result["status"]="false";
2031
 
2032
			#設置執行錯誤
2033
			$result["error"]=$checkArguments;
2034
 
2035
			#回傳結果
2036
			return $result;
2037
 
2038
			}#if end
2039
 
2040
		#取得resouce的參考
2041
		$resource=&$conf["info"]["resource"];
2042
 
2043
		#針對每個資源
2044
		foreach($resource as $rid => $info){
2045
 
2046
			#檢查參數
2047
			#函式說明:
2048
			#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
2049
			#回傳結果:
2050
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2051
			#$result["error"],執行不正常結束的錯訊息陣列.
2052
			#$result["simpleError"],簡單表示的錯誤訊息.
2053
			#$result["function"],當前執行的函式名稱.
2054
			#$result["argu"],設置給予的參數.
2055
			#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2056
			#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2057
			#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2058
			#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
2059
			#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
2060
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2061
			#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2062
			#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2063
			#必填參數:
2064
			#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2065
			$conf["variableCheck::checkArguments"]["varInput"]=$info;
2066
			#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2067
			$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2068
			#可省略參數:
2069
			#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2070
			$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("value","type","life");
2071
			#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
2072
			$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array(null,"string",integer);
2073
			#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
2074
			#$conf["canBeEmptyString"]="false";
2075
			#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
2076
			#$conf["canNotBeEmpty"]=array();
2077
			#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
2078
			#$conf["canBeEmpty"]=array();
2079
			#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
2080
			#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("action");
2081
			#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2082
			#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("condition","value","type");
2083
			#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
2084
			#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array",null,"string");
2085
			#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2086
			#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array(),null,null);
2087
			#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
2088
			#$conf["disallowAllSkipableVarIsEmpty"]="";
2089
			#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
2090
			#$conf["disallowAllSkipableVarIsEmptyArray"]="";
2091
			#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
2092
			#$conf["disallowAllSkipableVarNotExist"]="";
2093
			#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2094
			#$conf["arrayCountEqualCheck"][]=array();
2095
			#參考資料:
2096
			#array_keys=>http://php.net/manual/en/function.array-keys.php
2097
			#備註:
2098
			#無.
2099
			$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2100
			unset($conf["variableCheck::checkArguments"]);
2101
 
2102
			#如果執行異常
2103
			if($checkArguments["status"]==="false"){
2104
 
2105
				#設置執行異常識別
2106
				$result["status"]="false";
2107
 
2108
				#設置執行錯誤
2109
				$result["error"]=$checkArguments;
2110
 
2111
				#回傳結果
2112
				return $result;
2113
 
2114
				}#if end
2115
 
2116
			#如果檢查不通過
2117
			if($checkArguments["passed"]==="false"){
2118
 
2119
				#設置執行異常識別
2120
				$result["status"]="false";
2121
 
2122
				#設置執行錯誤
2123
				$result["error"]=$checkArguments;
2124
 
2125
				#回傳結果
2126
				return $result;
2127
 
2128
				}#if end
2129
 
2130
			#如果 life 過期
2131
			if(time()>$info["life"]){
2132
 
2133
				#如果是 php_variable 的資源
2134
				if($info["type"]==="php_variable"){
2135
 
2136
					#移除之
2137
					unset($resource[$rid]);
2138
 
2139
					}#if end
2140
 
2141
				#反之如果是 proc 的自選
2142
				else if($info["type"]==="proc"){
2143
 
2144
					#關閉之
2145
					proc_close($info["value"]);
2146
 
2147
					#移除之
2148
					unset($resource[$rid]);
2149
 
2150
					}#if end
2151
 
2152
				#反之為不應該有的類型
2153
				else{
2154
 
2155
					#設置執行異常識別
2156
					$result["status"]="false";
2157
 
2158
					#設置執行錯誤
2159
					$result["error"][]="invalid resource type:".$info["type"];
2160
 
2161
					#設置執行錯誤
2162
					$result["error"][]=$info;
2163
 
2164
					#回傳結果
2165
					return $result;
2166
 
2167
					}#else end
2168
 
2169
				}#if end
2170
 
2171
			}#foreach end
2172
 
2173
		#設置執行正常
2174
		$result["status"]="true";
327 liveuser 2175
 
339 liveuser 2176
		#回傳結果
2177
		return $result;
2178
 
2179
		}#function funcToRunWhenIdle end
2180
 
2181
	/*
2182
	#函式說明:
2183
	#給 server 結束前呼叫的 callback 函式.
2184
	#回傳結果:
2185
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2186
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
2187
	#$result["function"],當前執行的函式名稱.
2188
	#必填參數:
2189
	#$conf["info"],陣列,資料庫資訊.
2190
	$conf["info"]=array();
2191
	#$conf["serverCache"],陣列,只有server可以看到的cache.
2192
	$conf["serverCache"]=array();
2193
	#$conf["clientCache"],陣列,給予所有用戶的cache.
2194
	$conf["clientCache"]=array();
2195
	#可省略參數:
2196
	#無.
2197
	#參考資料:
2198
	#無.
2199
	#備註:
2200
	#無.
2201
	*/
2202
	public static function closeAllResurce(&$conf){
2203
 
2204
		#初始化要回傳的結果
2205
		$result=array();
327 liveuser 2206
 
339 liveuser 2207
		#取得當前執行的函數名稱
2208
		$result["function"]=__FUNCTION__;
2209
 
2210
		#如果沒有參數
2211
		if(func_num_args()==0){
2212
 
2213
			#設置執行失敗
2214
			$result["status"]="false";
2215
 
2216
			#設置執行錯誤訊息
2217
			$result["error"]="函數".$result["function"]."需要參數";
2218
 
2219
			#回傳結果
2220
			return $result;
2221
 
2222
			}#if end
2223
 
2224
		#涵式說明:
2225
		#判斷當前環境為web還是cmd
2226
		#回傳結果:
2227
		#$result,"web"或"cmd"
2228
		if(csInformation::getEnv()==="web"){
2229
 
2230
			#設置執行失敗
2231
			$result["status"]="false";
2232
 
2233
			#設置執行錯誤訊息
2234
			$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
2235
 
2236
			#回傳結果
2237
			return $result;
2238
 
2239
			}#if end
2240
 
2241
		#取得參數
2242
		$result["argu"]=$conf;
2243
 
2244
		#如果 $conf 不為陣列
2245
		if(gettype($conf)!=="array"){
2246
 
2247
			#設置執行失敗
2248
			$result["status"]="false";
2249
 
2250
			#設置執行錯誤訊息
2251
			$result["error"][]="\$conf變數須為陣列形態";
2252
 
2253
			#如果傳入的參數為 null
2254
			if(is_null($conf)){
2255
 
2256
				#設置執行錯誤訊息
2257
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2258
 
2259
				}#if end
2260
 
2261
			#回傳結果
2262
			return $result;
2263
 
2264
			}#if end
2265
 
2266
		#檢查參數
2267
		#函式說明:
2268
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
2269
		#回傳結果:
2270
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2271
		#$result["error"],執行不正常結束的錯訊息陣列.
2272
		#$result["simpleError"],簡單表示的錯誤訊息.
2273
		#$result["function"],當前執行的函式名稱.
2274
		#$result["argu"],設置給予的參數.
2275
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2276
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2277
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2278
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
2279
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
2280
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2281
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2282
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2283
		#必填參數:
2284
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2285
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2286
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2287
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2288
		#可省略參數:
2289
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2290
		#$conf["mustBeFilledVariableName"]=array();
2291
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
2292
		#$conf["mustBeFilledVariableType"]=array();
2293
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
2294
		#$conf["canBeEmptyString"]="false";
2295
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
2296
		#$conf["canNotBeEmpty"]=array();
2297
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
2298
		#$conf["canBeEmpty"]=array();
2299
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
2300
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("serverCache","clientCache");
2301
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2302
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("info","serverCache","clientCache");
2303
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
2304
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","array");
2305
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2306
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($sock);
2307
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
2308
		#$conf["disallowAllSkipableVarIsEmpty"]="";
2309
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
2310
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
2311
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
2312
		#$conf["disallowAllSkipableVarNotExist"]="";
2313
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2314
		#$conf["arrayCountEqualCheck"][]=array();
2315
		#參考資料:
2316
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2317
		#備註:
2318
		#無.
2319
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2320
		unset($conf["variableCheck::checkArguments"]);
2321
 
2322
		#如果執行異常
2323
		if($checkArguments["status"]==="false"){
2324
 
2325
			#設置執行異常識別
2326
			$result["status"]="false";
2327
 
2328
			#設置執行錯誤
2329
			$result["error"]=$checkArguments;
2330
 
2331
			#回傳結果
2332
			return $result;
2333
 
2334
			}#if end
2335
 
2336
		#如果檢查不通過
2337
		if($checkArguments["passed"]==="false"){
2338
 
2339
			#設置執行異常識別
2340
			$result["status"]="false";
2341
 
2342
			#設置執行錯誤
2343
			$result["error"]=$checkArguments;
2344
 
2345
			#回傳結果
2346
			return $result;
2347
 
2348
			}#if end
2349
 
2350
		#針對每個資源
2351
		foreach($conf["info"]["resouce"] as $id => $resource){
2352
 
2353
			#如果是 proc 類型
2354
			if($resource["type"]==="proc"){
2355
 
2356
				#proc_close資源,避免系統出錯
2357
				proc_close($resource["value"]);
2358
 
2359
				}#if end
2360
 
2361
			}#foreach end
2362
 
2363
		}#function closeAllResurce end
341 liveuser 2364
 
2365
	/*
2366
	#函式說明:
2367
	#存取快取服務.
2368
	#回傳結果:
2369
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2370
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
2371
	#$result["function"],當前執行的函式名稱.
2372
	#$result["argu"],所使用的參數.
2373
	#$result["content"],得到的回應字串.
2374
	#必填參數:
2375
	#$conf["action"],字串,"read":代表要讀取資料;"write":代表要寫入資料.
2376
	#$conf["action"]="";
2377
	#$conf["type"],字串,"php_variable":php的變數;"proc",透過proc運行的程序,可透過標準輸入進行操作.
2378
	#$conf["type"]="";
2379
	#可省略參數:
2380
	#$conf["value"],null,"action"參數為write時,資源的內容,形態不固定.
2381
	#$conf["value"]=null;
2382
	#$conf["sock"],字串,unix domain socket的路徑與名稱,預設為相對於當前套件的 var/qbpwcf/resource.sock
2383
	#$conf["sock"]="";
2384
	#$conf["condition"],陣列,條件,預設為空陣列,代表沒有條件,通常是為新增資源,元素的key為"id"者代表目標資源的id;元素的key為"value"者代表目標資源是否相等於"value",且"type"為"php_variable";元素的key為"pid"者代表運行的資源程序pid,且"type"為"proc"
2385
	#$conf["condition"]=array();
2386
	#參考資料:
2387
	#無.
2388
	#備註:
2389
	#僅能在命令列環境下運行.
2390
	*/
2391
	public static function client(&$conf){
2392
 
2393
		#初始化要回傳的結果
2394
		$result=array();
339 liveuser 2395
 
341 liveuser 2396
		#取得當前執行的函數名稱
2397
		$result["function"]=__FUNCTION__;
2398
 
2399
		#如果沒有參數
2400
		if(func_num_args()==0){
2401
 
2402
			#設置執行失敗
2403
			$result["status"]="false";
2404
 
2405
			#設置執行錯誤訊息
2406
			$result["error"]="函數".$result["function"]."需要參數";
2407
 
2408
			#回傳結果
2409
			return $result;
2410
 
2411
			}#if end
2412
 
2413
		#涵式說明:
2414
		#判斷當前環境為web還是cmd
2415
		#回傳結果:
2416
		#$result,"web"或"cmd"
2417
		if(csInformation::getEnv()==="web"){
2418
 
2419
			#設置執行失敗
2420
			$result["status"]="false";
2421
 
2422
			#設置執行錯誤訊息
2423
			$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
2424
 
2425
			#回傳結果
2426
			return $result;
2427
 
2428
			}#if end
2429
 
2430
		#取得參數
2431
		$result["argu"]=$conf;
2432
 
2433
		#如果 $conf 不為陣列
2434
		if(gettype($conf)!=="array"){
2435
 
2436
			#設置執行失敗
2437
			$result["status"]="false";
2438
 
2439
			#設置執行錯誤訊息
2440
			$result["error"][]="\$conf變數須為陣列形態";
2441
 
2442
			#如果傳入的參數為 null
2443
			if(is_null($conf)){
2444
 
2445
				#設置執行錯誤訊息
2446
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2447
 
2448
				}#if end
2449
 
2450
			#回傳結果
2451
			return $result;
2452
 
2453
			}#if end
2454
 
2455
		#預設的 unix domain socket addr
2456
		$sock=pathinfo(__FILE__)["dirname"]."/../../var/qbpwcf/resource.sock";
2457
 
2458
		#檢查參數
2459
		#函式說明:
2460
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
2461
		#回傳結果:
2462
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2463
		#$result["error"],執行不正常結束的錯訊息陣列.
2464
		#$result["simpleError"],簡單表示的錯誤訊息.
2465
		#$result["function"],當前執行的函式名稱.
2466
		#$result["argu"],設置給予的參數.
2467
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2468
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2469
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2470
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
2471
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
2472
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2473
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2474
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2475
		#必填參數:
2476
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2477
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2478
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2479
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2480
		#可省略參數:
2481
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2482
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("action","type");
2483
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
2484
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
2485
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
2486
		#$conf["canBeEmptyString"]="false";
2487
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
2488
		#$conf["canNotBeEmpty"]=array();
2489
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
2490
		#$conf["canBeEmpty"]=array();
2491
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
2492
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sock");
2493
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2494
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("value","sock","condition");
2495
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
2496
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array(null,"string","array");
2497
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2498
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,$sock,array());
2499
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
2500
		#$conf["disallowAllSkipableVarIsEmpty"]="";
2501
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
2502
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
2503
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
2504
		#$conf["disallowAllSkipableVarNotExist"]="";
2505
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2506
		#$conf["arrayCountEqualCheck"][]=array();
2507
		#參考資料:
2508
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2509
		#備註:
2510
		#無.
2511
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2512
		unset($conf["variableCheck::checkArguments"]);
2513
 
2514
		#如果執行異常
2515
		if($checkArguments["status"]==="false"){
2516
 
2517
			#設置執行異常識別
2518
			$result["status"]="false";
2519
 
2520
			#設置執行錯誤
2521
			$result["error"]=$checkArguments;
2522
 
2523
			#回傳結果
2524
			return $result;
2525
 
2526
			}#if end
2527
 
2528
		#如果檢查不通過
2529
		if($checkArguments["passed"]==="false"){
2530
 
2531
			#設置執行異常識別
2532
			$result["status"]="false";
2533
 
2534
			#設置執行錯誤
2535
			$result["error"]=$checkArguments;
2536
 
2537
			#回傳結果
2538
			return $result;
2539
 
2540
			}#if end
2541
 
2542
		#初始化要傳遞的內容
2543
		$request=array();
2544
 
368 liveuser 2545
		#設置要傳送的 data
2546
		$request["data"]["action"]=$conf["action"];
341 liveuser 2547
 
368 liveuser 2548
		#設置要傳送的 type
2549
		$request["data"]["type"]=$conf["type"];
341 liveuser 2550
 
368 liveuser 2551
		#設置condition
2552
		$request["data"]["condition"]=$conf["condition"];
2553
 
2554
		#如果有 value
341 liveuser 2555
		if(isset($conf["value"])){
2556
 
368 liveuser 2557
			#設置 value
2558
			$request["data"]["value"]=$conf["value"];
341 liveuser 2559
 
2560
			}#if end
2561
 
2562
		#連線到 unix domain socket,傳遞訊息,取得回應.
2563
		#連線到 sock::unixDomainSocketServer 產生的  unix domain socket,傳送指定的訊息.
2564
		#回傳結果:
2565
		#$result["status"],"true"代表執行正常;"false"代表執行不正常.
2566
		#$result["error"],錯誤訊息陣列.
2567
		#$result["function"],當前執行的函式名稱.
2568
		#$result["argu"],使用的參數.
2569
		#$result["content"],得到的回應.
2570
		#必填參數:
2571
		#$conf["msg"],陣列,要傳送的訊息,其主$conf["msg"]["id"],是無法指定的.
2572
		$conf["sock::sendAnyMsgToQBPWCFunixSocket"]["msg"]=$request;
2573
		#可省略參數:
2574
		#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
2575
		$conf["sock::sendAnyMsgToQBPWCFunixSocket"]["sock"]=$conf["sock"];
2576
		#參考資料:
2577
		#無.
2578
		#備註:
2579
		#無.
2580
		$sendAnyMsgToQBPWCFunixSocket=sock::sendAnyMsgToQBPWCFunixSocket($conf["sock::sendAnyMsgToQBPWCFunixSocket"]);
2581
		unset($conf["sock::sendAnyMsgToQBPWCFunixSocket"]);
2582
 
2583
		#如果執行異常
2584
		if($sendAnyMsgToQBPWCFunixSocket["status"]==="false"){
2585
 
2586
			#設置執行異常識別
2587
			$result["status"]="false";
2588
 
2589
			#設置執行錯誤
2590
			$result["error"]=$sendAnyMsgToQBPWCFunixSocket;
2591
 
2592
			#回傳結果
2593
			return $result;
2594
 
2595
			}#if end
2596
 
2597
		#設置得到的回應
2598
		$result["content"]=$sendAnyMsgToQBPWCFunixSocket["content"];
2599
 
2600
		#設置執行正常
2601
		$result["status"]="true";
2602
 
2603
		#回傳結果
2604
		return $result;
2605
 
2606
		}#function client end
2607
 
327 liveuser 2608
	}#classs refedosource end