| 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");
|
| 383 |
liveuser |
546 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("data","id");
|
| 368 |
liveuser |
547 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
| 383 |
liveuser |
548 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("object","string");
|
| 368 |
liveuser |
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 |
|
| 383 |
liveuser |
606 |
#另存參考
|
|
|
607 |
$crd=&$conf["request"]["data"];
|
|
|
608 |
|
|
|
609 |
#變更為陣列
|
|
|
610 |
$crd=(array)$crd;
|
|
|
611 |
|
| 368 |
liveuser |
612 |
#檢查參數
|
|
|
613 |
#函式說明:
|
|
|
614 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
615 |
#回傳結果:
|
|
|
616 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
617 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
618 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
619 |
#$result["function"],當前執行的函式名稱.
|
|
|
620 |
#$result["argu"],設置給予的參數.
|
|
|
621 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
622 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
623 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
624 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
625 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
626 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
627 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
628 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
629 |
#必填參數:
|
|
|
630 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 383 |
liveuser |
631 |
$conf["variableCheck::checkArguments"]["varInput"]=$crd;
|
| 368 |
liveuser |
632 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
633 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
634 |
#可省略參數:
|
|
|
635 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
| 327 |
liveuser |
636 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("action");
|
|
|
637 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
|
|
638 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
639 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
640 |
#$conf["canBeEmptyString"]="false";
|
|
|
641 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
642 |
#$conf["canNotBeEmpty"]=array();
|
|
|
643 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
644 |
#$conf["canBeEmpty"]=array();
|
|
|
645 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
646 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("action");
|
|
|
647 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
648 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("condition","value","type");
|
|
|
649 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
650 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array",null,"string");
|
|
|
651 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
652 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array(),null,null);
|
|
|
653 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
654 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
655 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
656 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
657 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
658 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
659 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
660 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
661 |
#參考資料:
|
|
|
662 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
663 |
#備註:
|
|
|
664 |
#無.
|
|
|
665 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
666 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
667 |
|
|
|
668 |
#如果執行異常
|
|
|
669 |
if($checkArguments["status"]==="false"){
|
|
|
670 |
|
|
|
671 |
#設置執行異常識別
|
|
|
672 |
$result["status"]="false";
|
|
|
673 |
|
|
|
674 |
#設置執行錯誤
|
|
|
675 |
$result["error"]=$checkArguments;
|
|
|
676 |
|
|
|
677 |
#回傳結果
|
|
|
678 |
return $result;
|
|
|
679 |
|
|
|
680 |
}#if end
|
|
|
681 |
|
|
|
682 |
#如果檢查不通過
|
|
|
683 |
if($checkArguments["passed"]==="false"){
|
|
|
684 |
|
|
|
685 |
#設置執行異常識別
|
|
|
686 |
$result["status"]="false";
|
|
|
687 |
|
|
|
688 |
#設置執行錯誤
|
|
|
689 |
$result["error"]=$checkArguments;
|
|
|
690 |
|
|
|
691 |
#回傳結果
|
|
|
692 |
return $result;
|
|
|
693 |
|
|
|
694 |
}#if end
|
|
|
695 |
|
| 368 |
liveuser |
696 |
#取得 request data 的參考
|
|
|
697 |
$rdata=&$conf["request"]["data"];
|
|
|
698 |
|
| 327 |
liveuser |
699 |
#判斷 action
|
| 368 |
liveuser |
700 |
switch($rdata["action"]){
|
| 327 |
liveuser |
701 |
|
|
|
702 |
#如果是要寫入
|
|
|
703 |
case "write":
|
|
|
704 |
|
|
|
705 |
#如果是空的,亦即沒有條件
|
| 368 |
liveuser |
706 |
if(empty($rdata["condition"])){
|
| 327 |
liveuser |
707 |
|
|
|
708 |
#代表要新增資料
|
|
|
709 |
|
|
|
710 |
#判斷類型
|
| 368 |
liveuser |
711 |
switch($rdata["type"]){
|
| 327 |
liveuser |
712 |
|
|
|
713 |
#如果是 php 變數
|
|
|
714 |
case "php_variable":
|
|
|
715 |
|
|
|
716 |
#產生id
|
|
|
717 |
#函式說明:
|
|
|
718 |
#使用 linux 的 uuid 指令來產生 uuid 字串
|
|
|
719 |
#回傳結果:
|
|
|
720 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
721 |
#$result["error"],錯誤訊息.
|
|
|
722 |
#$result["function"],當前執行的函式名稱.
|
|
|
723 |
#$result["content"],uuid.
|
|
|
724 |
#必填參數:
|
|
|
725 |
#無.
|
|
|
726 |
#可省略參數:
|
|
|
727 |
#無.
|
|
|
728 |
#參考資料:
|
|
|
729 |
#無.
|
|
|
730 |
#備註:
|
|
|
731 |
#無.
|
|
|
732 |
$uuid=cmd::uuid();
|
|
|
733 |
|
|
|
734 |
#如果執行異常
|
|
|
735 |
if($uuid["status"]==="false"){
|
|
|
736 |
|
|
|
737 |
#設置執行異常識別
|
|
|
738 |
$result["status"]="false";
|
|
|
739 |
|
|
|
740 |
#設置執行錯誤
|
|
|
741 |
$result["error"]=$uuid;
|
|
|
742 |
|
|
|
743 |
#回傳結果
|
|
|
744 |
return $result;
|
|
|
745 |
|
|
|
746 |
}#if end
|
|
|
747 |
|
|
|
748 |
#取得uuid
|
|
|
749 |
$uuid=$uuid["content"];
|
|
|
750 |
|
|
|
751 |
#初始化要設置的列
|
|
|
752 |
$row=array();
|
|
|
753 |
|
|
|
754 |
#設置存放的數值
|
| 368 |
liveuser |
755 |
$row["value"]=$rdata["value"];
|
| 327 |
liveuser |
756 |
|
|
|
757 |
#設置形態
|
| 368 |
liveuser |
758 |
$row["type"]=$rdata["type"];
|
| 327 |
liveuser |
759 |
|
| 339 |
liveuser |
760 |
#若無設定 life
|
| 368 |
liveuser |
761 |
if(!isset($rdata["life"])){
|
| 339 |
liveuser |
762 |
|
|
|
763 |
#設置預設的life
|
|
|
764 |
$row["life"]=time()+$conf["info"]["defaultLifeTime"];
|
|
|
765 |
|
|
|
766 |
}#if end
|
|
|
767 |
|
| 327 |
liveuser |
768 |
#新增資料並指定 id
|
|
|
769 |
$conf["info"]["resource"][$uuid]=$row;
|
|
|
770 |
|
|
|
771 |
#設置新增的資料
|
|
|
772 |
$result["content"]=array("id"=>$uuid,"info"=>$row);
|
|
|
773 |
|
|
|
774 |
#設置執行正常
|
|
|
775 |
$result["status"]="true";
|
|
|
776 |
|
|
|
777 |
#回傳結果
|
|
|
778 |
return $result;
|
|
|
779 |
|
|
|
780 |
#跳出 switch
|
|
|
781 |
break 2;
|
|
|
782 |
|
|
|
783 |
#若是 proc
|
|
|
784 |
case "proc":
|
|
|
785 |
|
|
|
786 |
#取得要運行的程式與參數
|
| 368 |
liveuser |
787 |
$cmdAndArgu=$rdata["value"];
|
| 327 |
liveuser |
788 |
|
|
|
789 |
#函式說明:
|
|
|
790 |
#透過proc來多執行序運作.
|
|
|
791 |
#回傳結果:
|
|
|
792 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
793 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
794 |
#$result["function"],當前執行的函式名稱.
|
|
|
795 |
#$result["argu"],使用的參數.
|
|
|
796 |
#$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"代表程序的資訊.
|
|
|
797 |
#必填參數:
|
|
|
798 |
#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
|
|
|
799 |
$conf["threads::proc"]["cmds"]=array($cmdAndArgu);
|
|
|
800 |
#可省略參數:
|
|
|
801 |
#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
|
|
|
802 |
$conf["threads::proc"]["wait"]="false";
|
|
|
803 |
#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
|
|
|
804 |
#$conf["timeout"]=array("10");
|
|
|
805 |
#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
|
|
|
806 |
#$conf["workingDir"]=array("path");
|
|
|
807 |
#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
|
|
|
808 |
#$conf["envs"]=array(array("key"=>"value"));
|
|
|
809 |
#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
|
|
|
810 |
#$conf["executeBy"]=array("bash");
|
|
|
811 |
#參考資料:
|
|
|
812 |
#https://www.php.net/manual/en/function.proc-open.php
|
|
|
813 |
#https://www.php.net/manual/en/function.proc-get-status.php
|
|
|
814 |
#https://www.php.net/manual/en/function.proc-terminate.php
|
|
|
815 |
#備註:
|
|
|
816 |
#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
|
|
|
817 |
#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
|
|
|
818 |
$proc=threads::proc($conf["threads::proc"]);
|
|
|
819 |
unset($conf["threads::proc"]);
|
|
|
820 |
|
|
|
821 |
#如果執行異常
|
|
|
822 |
if($proc["status"]==="false"){
|
|
|
823 |
|
|
|
824 |
#設置跳過,不適用
|
|
|
825 |
$result["status"]="continue";
|
|
|
826 |
|
|
|
827 |
#回傳結果
|
|
|
828 |
return $result;
|
|
|
829 |
|
|
|
830 |
}#if end
|
|
|
831 |
|
|
|
832 |
#函式說明:
|
|
|
833 |
#更新透過proc執行的多程序資訊.
|
|
|
834 |
#回傳結果:
|
|
|
835 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
836 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
837 |
#$result["function"],當前執行的函式名稱.
|
|
|
838 |
#$result["argu"],使用的參數.
|
|
|
839 |
#$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"代表程序的資訊.
|
|
|
840 |
#必填參數:
|
|
|
841 |
#$conf["procs"],陣列,運行self::proc後回傳的content.
|
|
|
842 |
$conf["threads::proc_update"]["procs"]=$procs["content"];
|
|
|
843 |
#可省略參數:
|
|
|
844 |
#無.
|
|
|
845 |
#參考資料:
|
|
|
846 |
#無.
|
|
|
847 |
#備註:
|
|
|
848 |
#無.
|
|
|
849 |
$proc_update=threads::proc_update($conf["threads::proc_update"]);
|
|
|
850 |
unset($conf["threads::proc_update"]);
|
|
|
851 |
|
|
|
852 |
#如果執行異常
|
|
|
853 |
if($proc_update["status"]==="false"){
|
|
|
854 |
|
|
|
855 |
#設置跳過,不適用
|
|
|
856 |
$result["status"]="continue";
|
|
|
857 |
|
|
|
858 |
#回傳結果
|
|
|
859 |
return $result;
|
|
|
860 |
|
|
|
861 |
}#if end
|
|
|
862 |
|
|
|
863 |
#如果proc裡面的程式執行異常
|
|
|
864 |
if($proc_update["content"]["status"]==="false"){
|
|
|
865 |
|
|
|
866 |
#設置跳過,不適用
|
|
|
867 |
$result["status"]="continue";
|
|
|
868 |
|
|
|
869 |
#回傳結果
|
|
|
870 |
return $result;
|
|
|
871 |
|
|
|
872 |
}#if end
|
|
|
873 |
|
|
|
874 |
#取得要儲存的php變數
|
| 339 |
liveuser |
875 |
$value=$proc_update["content"][0];
|
| 327 |
liveuser |
876 |
|
|
|
877 |
#產生id
|
|
|
878 |
#函式說明:
|
|
|
879 |
#使用 linux 的 uuid 指令來產生 uuid 字串
|
|
|
880 |
#回傳結果:
|
|
|
881 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
882 |
#$result["error"],錯誤訊息.
|
|
|
883 |
#$result["function"],當前執行的函式名稱.
|
|
|
884 |
#$result["content"],uuid.
|
|
|
885 |
#必填參數:
|
|
|
886 |
#無.
|
|
|
887 |
#可省略參數:
|
|
|
888 |
#無.
|
|
|
889 |
#參考資料:
|
|
|
890 |
#無.
|
|
|
891 |
#備註:
|
|
|
892 |
#無.
|
|
|
893 |
$uuid=cmd::uuid();
|
|
|
894 |
|
|
|
895 |
#如果執行異常
|
|
|
896 |
if($uuid["status"]==="false"){
|
|
|
897 |
|
|
|
898 |
#設置執行異常識別
|
|
|
899 |
$result["status"]="false";
|
|
|
900 |
|
|
|
901 |
#設置執行錯誤
|
|
|
902 |
$result["error"]=$uuid;
|
|
|
903 |
|
|
|
904 |
#回傳結果
|
|
|
905 |
return $result;
|
|
|
906 |
|
|
|
907 |
}#if end
|
|
|
908 |
|
|
|
909 |
#取得uuid
|
|
|
910 |
$uuid=$uuid["content"];
|
|
|
911 |
|
|
|
912 |
#初始化要設置的列
|
|
|
913 |
$row=array();
|
|
|
914 |
|
|
|
915 |
#設置存放的數值
|
|
|
916 |
$row["value"]=$value;
|
|
|
917 |
|
|
|
918 |
#設置形態
|
| 368 |
liveuser |
919 |
$row["type"]=$rdata["type"];
|
| 327 |
liveuser |
920 |
|
|
|
921 |
#新增資料並指定 id
|
|
|
922 |
$conf["info"]["resource"][$uuid]=$row;
|
|
|
923 |
|
| 339 |
liveuser |
924 |
#若無設定 life
|
| 368 |
liveuser |
925 |
if(!isset($rdata["life"])){
|
| 339 |
liveuser |
926 |
|
|
|
927 |
#設置預設的life
|
|
|
928 |
$row["life"]=time()+$conf["info"]["defaultLifeTime"];
|
|
|
929 |
|
|
|
930 |
}#if end
|
|
|
931 |
|
| 327 |
liveuser |
932 |
#設置新增的資料
|
|
|
933 |
$result["content"]=array("id"=>$uuid,"info"=>$row);
|
|
|
934 |
|
|
|
935 |
#設置執行正常
|
|
|
936 |
$result["status"]="true";
|
|
|
937 |
|
|
|
938 |
#回傳結果
|
|
|
939 |
return $result;
|
|
|
940 |
|
|
|
941 |
#跳出 switch
|
|
|
942 |
break 2;
|
|
|
943 |
|
|
|
944 |
#其他類型
|
|
|
945 |
default:
|
|
|
946 |
|
|
|
947 |
#設置錯誤訊息
|
| 368 |
liveuser |
948 |
$result["error"][]="unsupported type:".$rdata["type"];
|
| 327 |
liveuser |
949 |
|
|
|
950 |
#設置執行異常
|
|
|
951 |
$result["status"]="false";
|
|
|
952 |
|
|
|
953 |
#回傳結果
|
|
|
954 |
return $result;
|
|
|
955 |
|
|
|
956 |
}#switch end
|
|
|
957 |
|
|
|
958 |
}#if end
|
|
|
959 |
|
|
|
960 |
#反之有條件
|
|
|
961 |
else{
|
|
|
962 |
|
|
|
963 |
#針對每個條件
|
| 368 |
liveuser |
964 |
foreach($rdata["condition"] as $key => $val){
|
| 327 |
liveuser |
965 |
|
|
|
966 |
#判斷 $key
|
|
|
967 |
switch($key){
|
|
|
968 |
|
|
|
969 |
#如果條件欄位是 id
|
|
|
970 |
case "id":
|
|
|
971 |
|
|
|
972 |
#針對每筆記錄
|
|
|
973 |
foreach($conf["info"]["resource"] as $idInM => $valInM){
|
|
|
974 |
|
|
|
975 |
#如果找到符合id的資料
|
|
|
976 |
if($idInM===$val){
|
|
|
977 |
|
| 339 |
liveuser |
978 |
#取得現有資源類型
|
|
|
979 |
$currentType=$conf["info"]["resource"][$idInM]["type"];
|
|
|
980 |
|
|
|
981 |
#如果沒有指定新 type
|
| 368 |
liveuser |
982 |
if(!isset($rdata["type"])){
|
| 339 |
liveuser |
983 |
|
|
|
984 |
#視為跟現有資源類型一樣
|
| 368 |
liveuser |
985 |
$rdata["type"]=$currentType;
|
| 339 |
liveuser |
986 |
|
|
|
987 |
}#if end
|
|
|
988 |
|
|
|
989 |
#判斷新資源類型
|
| 368 |
liveuser |
990 |
switch($rdata["type"]){
|
| 339 |
liveuser |
991 |
|
|
|
992 |
#如果為 "php_variable"
|
|
|
993 |
case "php_variable":
|
|
|
994 |
|
|
|
995 |
#如果既有資源的類型為 "proc"
|
|
|
996 |
if($currentType==="proc"){
|
|
|
997 |
|
|
|
998 |
#pid
|
|
|
999 |
#$valInM["proc_get_status"]["pid"];
|
|
|
1000 |
|
|
|
1001 |
#關閉程序
|
|
|
1002 |
proc_close($valInM["process"]);
|
|
|
1003 |
|
|
|
1004 |
}#if end
|
|
|
1005 |
|
|
|
1006 |
#初始化要設置的列
|
|
|
1007 |
$row=array();
|
|
|
1008 |
|
|
|
1009 |
#設置存放的數值
|
| 368 |
liveuser |
1010 |
$row["value"]=$rdata["value"];
|
| 339 |
liveuser |
1011 |
|
|
|
1012 |
#設置形態
|
| 368 |
liveuser |
1013 |
$row["type"]=$rdata["type"];
|
| 339 |
liveuser |
1014 |
|
|
|
1015 |
#若無設定 life
|
| 368 |
liveuser |
1016 |
if(!isset($rdata["life"])){
|
| 339 |
liveuser |
1017 |
|
|
|
1018 |
#設置預設的life
|
|
|
1019 |
$row["life"]=time()+$conf["info"]["defaultLifeTime"];
|
|
|
1020 |
|
|
|
1021 |
}#if end
|
|
|
1022 |
|
|
|
1023 |
#寫入資源
|
|
|
1024 |
$conf["info"]["resource"][$idInM]=$row;
|
|
|
1025 |
|
|
|
1026 |
#跳出 switch
|
|
|
1027 |
break;
|
|
|
1028 |
|
|
|
1029 |
#如果為 "proc"
|
|
|
1030 |
case "proc":
|
|
|
1031 |
|
|
|
1032 |
#如果既有資源的類型為 "proc"
|
|
|
1033 |
if($currentType==="proc"){
|
|
|
1034 |
|
|
|
1035 |
#pid
|
|
|
1036 |
#$valInM["proc_get_status"]["pid"];
|
|
|
1037 |
|
|
|
1038 |
#關閉程序
|
|
|
1039 |
proc_close($valInM["process"]);
|
|
|
1040 |
|
|
|
1041 |
}#if end
|
|
|
1042 |
|
|
|
1043 |
#取得要運行的程式與參數
|
| 368 |
liveuser |
1044 |
$cmdAndArgu=$rdata["value"];
|
| 339 |
liveuser |
1045 |
|
|
|
1046 |
#函式說明:
|
|
|
1047 |
#透過proc來多執行序運作.
|
|
|
1048 |
#回傳結果:
|
|
|
1049 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1050 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1051 |
#$result["function"],當前執行的函式名稱.
|
|
|
1052 |
#$result["argu"],使用的參數.
|
|
|
1053 |
#$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"代表程序的資訊.
|
|
|
1054 |
#必填參數:
|
|
|
1055 |
#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
|
|
|
1056 |
$conf["threads::proc"]["cmds"]=array($cmdAndArgu);
|
|
|
1057 |
#可省略參數:
|
|
|
1058 |
#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
|
|
|
1059 |
$conf["threads::proc"]["wait"]="false";
|
|
|
1060 |
#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
|
|
|
1061 |
#$conf["timeout"]=array("10");
|
|
|
1062 |
#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
|
|
|
1063 |
#$conf["workingDir"]=array("path");
|
|
|
1064 |
#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
|
|
|
1065 |
#$conf["envs"]=array(array("key"=>"value"));
|
|
|
1066 |
#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
|
|
|
1067 |
#$conf["executeBy"]=array("bash");
|
|
|
1068 |
#參考資料:
|
|
|
1069 |
#https://www.php.net/manual/en/function.proc-open.php
|
|
|
1070 |
#https://www.php.net/manual/en/function.proc-get-status.php
|
|
|
1071 |
#https://www.php.net/manual/en/function.proc-terminate.php
|
|
|
1072 |
#備註:
|
|
|
1073 |
#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
|
|
|
1074 |
#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
|
|
|
1075 |
$proc=threads::proc($conf["threads::proc"]);
|
|
|
1076 |
unset($conf["threads::proc"]);
|
|
|
1077 |
|
|
|
1078 |
#如果執行異常
|
|
|
1079 |
if($proc["status"]==="false"){
|
|
|
1080 |
|
|
|
1081 |
#設置跳過,不適用
|
|
|
1082 |
$result["status"]="continue";
|
|
|
1083 |
|
|
|
1084 |
#回傳結果
|
|
|
1085 |
return $result;
|
|
|
1086 |
|
|
|
1087 |
}#if end
|
|
|
1088 |
|
|
|
1089 |
#函式說明:
|
|
|
1090 |
#更新透過proc執行的多程序資訊.
|
|
|
1091 |
#回傳結果:
|
|
|
1092 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1093 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1094 |
#$result["function"],當前執行的函式名稱.
|
|
|
1095 |
#$result["argu"],使用的參數.
|
|
|
1096 |
#$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"代表程序的資訊.
|
|
|
1097 |
#必填參數:
|
|
|
1098 |
#$conf["procs"],陣列,運行self::proc後回傳的content.
|
|
|
1099 |
$conf["threads::proc_update"]["procs"]=$procs["content"];
|
|
|
1100 |
#可省略參數:
|
|
|
1101 |
#無.
|
|
|
1102 |
#參考資料:
|
|
|
1103 |
#無.
|
|
|
1104 |
#備註:
|
|
|
1105 |
#無.
|
|
|
1106 |
$proc_update=threads::proc_update($conf["threads::proc_update"]);
|
|
|
1107 |
unset($conf["threads::proc_update"]);
|
|
|
1108 |
|
|
|
1109 |
#如果執行異常
|
|
|
1110 |
if($proc_update["status"]==="false"){
|
|
|
1111 |
|
|
|
1112 |
#設置跳過,不適用
|
|
|
1113 |
$result["status"]="continue";
|
|
|
1114 |
|
|
|
1115 |
#回傳結果
|
|
|
1116 |
return $result;
|
|
|
1117 |
|
|
|
1118 |
}#if end
|
|
|
1119 |
|
|
|
1120 |
#如果proc裡面的程式執行異常
|
|
|
1121 |
if($proc_update["content"]["status"]==="false"){
|
|
|
1122 |
|
|
|
1123 |
#設置跳過,不適用
|
|
|
1124 |
$result["status"]="continue";
|
|
|
1125 |
|
|
|
1126 |
#回傳結果
|
|
|
1127 |
return $result;
|
|
|
1128 |
|
|
|
1129 |
}#if end
|
|
|
1130 |
|
|
|
1131 |
#取得要儲存的php變數
|
|
|
1132 |
$value=$proc_update["content"][0];
|
|
|
1133 |
|
|
|
1134 |
#初始化要設置的列
|
|
|
1135 |
$row=array();
|
|
|
1136 |
|
|
|
1137 |
#設置存放的數值
|
|
|
1138 |
$row["value"]=$value;
|
|
|
1139 |
|
|
|
1140 |
#設置形態
|
| 368 |
liveuser |
1141 |
$row["type"]=$rdata["type"];
|
| 339 |
liveuser |
1142 |
|
|
|
1143 |
#若無設定 life
|
| 368 |
liveuser |
1144 |
if(!isset($rdata["life"])){
|
| 339 |
liveuser |
1145 |
|
|
|
1146 |
#設置預設的life
|
|
|
1147 |
$row["life"]=time()+$conf["info"]["defaultLifeTime"];
|
|
|
1148 |
|
|
|
1149 |
}#if end
|
|
|
1150 |
|
|
|
1151 |
#寫入資源
|
|
|
1152 |
$conf["info"]["resource"][$idInM]=$row;
|
|
|
1153 |
|
|
|
1154 |
#跳出 switch
|
|
|
1155 |
break;
|
|
|
1156 |
|
|
|
1157 |
#其他 type
|
|
|
1158 |
default:
|
|
|
1159 |
|
|
|
1160 |
#設置錯誤訊息
|
| 368 |
liveuser |
1161 |
$result["error"][]="unsupported type:".$rdata["type"];
|
| 339 |
liveuser |
1162 |
|
|
|
1163 |
#設置執行異常
|
|
|
1164 |
$result["status"]="false";
|
|
|
1165 |
|
|
|
1166 |
#回傳結果
|
|
|
1167 |
return $result;
|
|
|
1168 |
|
|
|
1169 |
}#switch end
|
|
|
1170 |
|
| 327 |
liveuser |
1171 |
#設置結果
|
| 339 |
liveuser |
1172 |
$result["content"]=array("id"=>$idInM,"value"=>$conf["info"]["resource"][$valInM]);
|
| 327 |
liveuser |
1173 |
|
|
|
1174 |
#設置執行正常
|
|
|
1175 |
$result["status"]="true";
|
|
|
1176 |
|
|
|
1177 |
#回傳結果
|
|
|
1178 |
return $result;
|
|
|
1179 |
|
|
|
1180 |
}#if end
|
|
|
1181 |
|
|
|
1182 |
}#foreach end
|
|
|
1183 |
|
|
|
1184 |
#執行到這邊代表沒有符合條件的記錄
|
|
|
1185 |
|
|
|
1186 |
#設置結果為null
|
|
|
1187 |
$result["content"]=null;
|
|
|
1188 |
|
|
|
1189 |
#設置執行正常
|
|
|
1190 |
$result["status"]="true";
|
|
|
1191 |
|
|
|
1192 |
#回傳結果
|
|
|
1193 |
return $result;
|
|
|
1194 |
|
|
|
1195 |
#跳出 switch
|
|
|
1196 |
break;
|
|
|
1197 |
|
|
|
1198 |
#如果條件欄位是 value
|
|
|
1199 |
case "value":
|
|
|
1200 |
|
| 339 |
liveuser |
1201 |
#針對每筆記錄
|
| 327 |
liveuser |
1202 |
foreach($conf["info"]["resource"] as $idInM => $valInM){
|
|
|
1203 |
|
|
|
1204 |
#如果不是 php_variable
|
|
|
1205 |
if($valInM["type"]!=="php_variable"){
|
|
|
1206 |
|
|
|
1207 |
#跳過之
|
|
|
1208 |
continue;
|
|
|
1209 |
|
|
|
1210 |
}#if end
|
|
|
1211 |
|
|
|
1212 |
#如果找到符合value的資料
|
|
|
1213 |
if($valInM===$val){
|
|
|
1214 |
|
| 339 |
liveuser |
1215 |
#如果沒有指定新 type
|
| 368 |
liveuser |
1216 |
if(!isset($rdata["type"])){
|
| 327 |
liveuser |
1217 |
|
| 339 |
liveuser |
1218 |
#視為跟現有資源類型一樣
|
| 368 |
liveuser |
1219 |
$rdata["type"]=$currentType;
|
| 327 |
liveuser |
1220 |
|
| 339 |
liveuser |
1221 |
}#if end
|
| 327 |
liveuser |
1222 |
|
| 339 |
liveuser |
1223 |
#判斷新資源類型
|
| 368 |
liveuser |
1224 |
switch($rdata["type"]){
|
| 339 |
liveuser |
1225 |
|
|
|
1226 |
#如果為 "php_variable"
|
|
|
1227 |
case "php_variable":
|
|
|
1228 |
|
|
|
1229 |
#如果既有資源的類型為 "proc"
|
|
|
1230 |
if($currentType==="proc"){
|
|
|
1231 |
|
|
|
1232 |
#pid
|
|
|
1233 |
#$valInM["proc_get_status"]["pid"];
|
|
|
1234 |
|
|
|
1235 |
#關閉程序
|
|
|
1236 |
proc_close($valInM["process"]);
|
|
|
1237 |
|
|
|
1238 |
}#if end
|
|
|
1239 |
|
|
|
1240 |
#初始化要設置的列
|
|
|
1241 |
$row=array();
|
|
|
1242 |
|
|
|
1243 |
#設置存放的數值
|
| 368 |
liveuser |
1244 |
$row["value"]=$rdata["value"];
|
| 339 |
liveuser |
1245 |
|
|
|
1246 |
#設置形態
|
| 368 |
liveuser |
1247 |
$row["type"]=$rdata["type"];
|
| 339 |
liveuser |
1248 |
|
|
|
1249 |
#若無設定 life
|
| 368 |
liveuser |
1250 |
if(!isset($rdata["life"])){
|
| 339 |
liveuser |
1251 |
|
|
|
1252 |
#設置預設的life
|
|
|
1253 |
$row["life"]=time()+$conf["info"]["defaultLifeTime"];
|
|
|
1254 |
|
|
|
1255 |
}#if end
|
|
|
1256 |
|
|
|
1257 |
#寫入資源
|
|
|
1258 |
$conf["info"]["resource"][$idInM]=$row;
|
|
|
1259 |
|
|
|
1260 |
#跳出 switch
|
|
|
1261 |
break;
|
|
|
1262 |
|
|
|
1263 |
#如果為 "proc"
|
|
|
1264 |
case "proc":
|
|
|
1265 |
|
|
|
1266 |
#如果既有資源的類型為 "proc"
|
|
|
1267 |
if($currentType==="proc"){
|
|
|
1268 |
|
|
|
1269 |
#pid
|
|
|
1270 |
#$valInM["proc_get_status"]["pid"];
|
|
|
1271 |
|
|
|
1272 |
#關閉程序
|
|
|
1273 |
proc_close($valInM["process"]);
|
|
|
1274 |
|
|
|
1275 |
}#if end
|
|
|
1276 |
|
|
|
1277 |
#取得要運行的程式與參數
|
| 368 |
liveuser |
1278 |
$cmdAndArgu=$rdata["value"];
|
| 339 |
liveuser |
1279 |
|
|
|
1280 |
#函式說明:
|
|
|
1281 |
#透過proc來多執行序運作.
|
|
|
1282 |
#回傳結果:
|
|
|
1283 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1284 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1285 |
#$result["function"],當前執行的函式名稱.
|
|
|
1286 |
#$result["argu"],使用的參數.
|
|
|
1287 |
#$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"代表程序的資訊.
|
|
|
1288 |
#必填參數:
|
|
|
1289 |
#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
|
|
|
1290 |
$conf["threads::proc"]["cmds"]=array($cmdAndArgu);
|
|
|
1291 |
#可省略參數:
|
|
|
1292 |
#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
|
|
|
1293 |
$conf["threads::proc"]["wait"]="false";
|
|
|
1294 |
#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
|
|
|
1295 |
#$conf["timeout"]=array("10");
|
|
|
1296 |
#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
|
|
|
1297 |
#$conf["workingDir"]=array("path");
|
|
|
1298 |
#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
|
|
|
1299 |
#$conf["envs"]=array(array("key"=>"value"));
|
|
|
1300 |
#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
|
|
|
1301 |
#$conf["executeBy"]=array("bash");
|
|
|
1302 |
#參考資料:
|
|
|
1303 |
#https://www.php.net/manual/en/function.proc-open.php
|
|
|
1304 |
#https://www.php.net/manual/en/function.proc-get-status.php
|
|
|
1305 |
#https://www.php.net/manual/en/function.proc-terminate.php
|
|
|
1306 |
#備註:
|
|
|
1307 |
#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
|
|
|
1308 |
#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
|
|
|
1309 |
$proc=threads::proc($conf["threads::proc"]);
|
|
|
1310 |
unset($conf["threads::proc"]);
|
|
|
1311 |
|
|
|
1312 |
#如果執行異常
|
|
|
1313 |
if($proc["status"]==="false"){
|
|
|
1314 |
|
|
|
1315 |
#設置跳過,不適用
|
|
|
1316 |
$result["status"]="continue";
|
|
|
1317 |
|
|
|
1318 |
#回傳結果
|
|
|
1319 |
return $result;
|
|
|
1320 |
|
|
|
1321 |
}#if end
|
|
|
1322 |
|
|
|
1323 |
#函式說明:
|
|
|
1324 |
#更新透過proc執行的多程序資訊.
|
|
|
1325 |
#回傳結果:
|
|
|
1326 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1327 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1328 |
#$result["function"],當前執行的函式名稱.
|
|
|
1329 |
#$result["argu"],使用的參數.
|
|
|
1330 |
#$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"代表程序的資訊.
|
|
|
1331 |
#必填參數:
|
|
|
1332 |
#$conf["procs"],陣列,運行self::proc後回傳的content.
|
|
|
1333 |
$conf["threads::proc_update"]["procs"]=$procs["content"];
|
|
|
1334 |
#可省略參數:
|
|
|
1335 |
#無.
|
|
|
1336 |
#參考資料:
|
|
|
1337 |
#無.
|
|
|
1338 |
#備註:
|
|
|
1339 |
#無.
|
|
|
1340 |
$proc_update=threads::proc_update($conf["threads::proc_update"]);
|
|
|
1341 |
unset($conf["threads::proc_update"]);
|
|
|
1342 |
|
|
|
1343 |
#如果執行異常
|
|
|
1344 |
if($proc_update["status"]==="false"){
|
|
|
1345 |
|
|
|
1346 |
#設置跳過,不適用
|
|
|
1347 |
$result["status"]="continue";
|
|
|
1348 |
|
|
|
1349 |
#回傳結果
|
|
|
1350 |
return $result;
|
|
|
1351 |
|
|
|
1352 |
}#if end
|
|
|
1353 |
|
|
|
1354 |
#如果proc裡面的程式執行異常
|
|
|
1355 |
if($proc_update["content"]["status"]==="false"){
|
|
|
1356 |
|
|
|
1357 |
#設置跳過,不適用
|
|
|
1358 |
$result["status"]="continue";
|
|
|
1359 |
|
|
|
1360 |
#回傳結果
|
|
|
1361 |
return $result;
|
|
|
1362 |
|
|
|
1363 |
}#if end
|
|
|
1364 |
|
|
|
1365 |
#取得要儲存的php變數
|
|
|
1366 |
$value=$proc_update["content"][0];
|
|
|
1367 |
|
|
|
1368 |
#初始化要設置的列
|
|
|
1369 |
$row=array();
|
|
|
1370 |
|
|
|
1371 |
#設置存放的數值
|
|
|
1372 |
$row["value"]=$value;
|
|
|
1373 |
|
|
|
1374 |
#設置形態
|
| 368 |
liveuser |
1375 |
$row["type"]=$rdata["type"];
|
| 339 |
liveuser |
1376 |
|
|
|
1377 |
#若無設定 life
|
| 368 |
liveuser |
1378 |
if(!isset($rdata["life"])){
|
| 339 |
liveuser |
1379 |
|
|
|
1380 |
#設置預設的life
|
|
|
1381 |
$row["life"]=time()+$conf["info"]["defaultLifeTime"];
|
|
|
1382 |
|
|
|
1383 |
}#if end
|
|
|
1384 |
|
|
|
1385 |
#寫入資源
|
|
|
1386 |
$conf["info"]["resource"][$idInM]=$row;
|
|
|
1387 |
|
|
|
1388 |
#跳出 switch
|
|
|
1389 |
break;
|
|
|
1390 |
|
|
|
1391 |
#其他 type
|
|
|
1392 |
default:
|
|
|
1393 |
|
|
|
1394 |
#設置錯誤訊息
|
| 368 |
liveuser |
1395 |
$result["error"][]="unsupported type:".$rdata["type"];
|
| 339 |
liveuser |
1396 |
|
|
|
1397 |
#設置執行異常
|
|
|
1398 |
$result["status"]="false";
|
|
|
1399 |
|
|
|
1400 |
#回傳結果
|
|
|
1401 |
return $result;
|
|
|
1402 |
|
|
|
1403 |
}#switch end
|
|
|
1404 |
|
| 327 |
liveuser |
1405 |
}#if end
|
|
|
1406 |
|
|
|
1407 |
}#foreach end
|
|
|
1408 |
|
|
|
1409 |
#執行到這邊代表沒有符合條件的記錄
|
|
|
1410 |
|
|
|
1411 |
#設置結果為null
|
|
|
1412 |
$result["content"]=null;
|
|
|
1413 |
|
|
|
1414 |
#設置執行正常
|
|
|
1415 |
$result["status"]="true";
|
|
|
1416 |
|
|
|
1417 |
#回傳結果
|
|
|
1418 |
return $result;
|
|
|
1419 |
|
|
|
1420 |
#跳出 switch
|
|
|
1421 |
break;
|
|
|
1422 |
|
|
|
1423 |
#如果條件欄位是 pid
|
|
|
1424 |
case "pid":
|
|
|
1425 |
|
| 339 |
liveuser |
1426 |
#針對每筆記錄
|
| 368 |
liveuser |
1427 |
foreach($rdata["resource"] as $idInM => $valInM){
|
| 327 |
liveuser |
1428 |
|
|
|
1429 |
#如果不是 proc
|
|
|
1430 |
if($valInM["type"]!=="proc"){
|
|
|
1431 |
|
|
|
1432 |
#跳過之
|
|
|
1433 |
continue;
|
|
|
1434 |
|
|
|
1435 |
}#if end
|
|
|
1436 |
|
|
|
1437 |
#取得 proc 的 pid
|
| 339 |
liveuser |
1438 |
$pidInM=$valInM["proc_get_status"]["pid"];
|
| 327 |
liveuser |
1439 |
|
|
|
1440 |
#如果找到符合value的資料
|
|
|
1441 |
if($pidInM===$val){
|
|
|
1442 |
|
| 339 |
liveuser |
1443 |
#如果沒有指定新 type
|
| 368 |
liveuser |
1444 |
if(!isset($rdata["type"])){
|
| 327 |
liveuser |
1445 |
|
| 339 |
liveuser |
1446 |
#視為跟現有資源類型一樣
|
| 368 |
liveuser |
1447 |
$rdata["type"]=$currentType;
|
| 327 |
liveuser |
1448 |
|
| 339 |
liveuser |
1449 |
}#if end
|
| 327 |
liveuser |
1450 |
|
| 339 |
liveuser |
1451 |
#判斷新資源類型
|
| 368 |
liveuser |
1452 |
switch($rdata["type"]){
|
| 339 |
liveuser |
1453 |
|
|
|
1454 |
#如果為 "php_variable"
|
|
|
1455 |
case "php_variable":
|
|
|
1456 |
|
|
|
1457 |
#如果既有資源的類型為 "proc"
|
|
|
1458 |
if($currentType==="proc"){
|
|
|
1459 |
|
|
|
1460 |
#pid
|
|
|
1461 |
#$valInM["proc_get_status"]["pid"];
|
|
|
1462 |
|
|
|
1463 |
#關閉程序
|
|
|
1464 |
proc_close($valInM["process"]);
|
|
|
1465 |
|
|
|
1466 |
}#if end
|
|
|
1467 |
|
|
|
1468 |
#初始化要設置的列
|
|
|
1469 |
$row=array();
|
|
|
1470 |
|
|
|
1471 |
#設置存放的數值
|
| 368 |
liveuser |
1472 |
$row["value"]=$rdata["value"];
|
| 339 |
liveuser |
1473 |
|
|
|
1474 |
#設置形態
|
| 368 |
liveuser |
1475 |
$row["type"]=rdata["request"]["type"];
|
| 339 |
liveuser |
1476 |
|
|
|
1477 |
#若無設定 life
|
| 368 |
liveuser |
1478 |
if(!isset($rdata["life"])){
|
| 339 |
liveuser |
1479 |
|
|
|
1480 |
#設置預設的life
|
|
|
1481 |
$row["life"]=time()+$conf["info"]["defaultLifeTime"];
|
|
|
1482 |
|
|
|
1483 |
}#if end
|
|
|
1484 |
|
|
|
1485 |
#寫入資源
|
|
|
1486 |
$conf["info"]["resource"][$idInM]=$row;
|
|
|
1487 |
|
|
|
1488 |
#跳出 switch
|
|
|
1489 |
break;
|
|
|
1490 |
|
|
|
1491 |
#如果為 "proc"
|
|
|
1492 |
case "proc":
|
|
|
1493 |
|
|
|
1494 |
#如果既有資源的類型為 "proc"
|
|
|
1495 |
if($currentType==="proc"){
|
|
|
1496 |
|
|
|
1497 |
#pid
|
|
|
1498 |
#$valInM["proc_get_status"]["pid"];
|
|
|
1499 |
|
|
|
1500 |
#關閉程序
|
|
|
1501 |
proc_close($valInM["process"]);
|
|
|
1502 |
|
|
|
1503 |
}#if end
|
|
|
1504 |
|
|
|
1505 |
#取得要運行的程式與參數
|
| 368 |
liveuser |
1506 |
$cmdAndArgu=$rdata["value"];
|
| 339 |
liveuser |
1507 |
|
|
|
1508 |
#函式說明:
|
|
|
1509 |
#透過proc來多執行序運作.
|
|
|
1510 |
#回傳結果:
|
|
|
1511 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1512 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1513 |
#$result["function"],當前執行的函式名稱.
|
|
|
1514 |
#$result["argu"],使用的參數.
|
|
|
1515 |
#$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"代表程序的資訊.
|
|
|
1516 |
#必填參數:
|
|
|
1517 |
#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
|
|
|
1518 |
$conf["threads::proc"]["cmds"]=array($cmdAndArgu);
|
|
|
1519 |
#可省略參數:
|
|
|
1520 |
#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
|
|
|
1521 |
$conf["threads::proc"]["wait"]="false";
|
|
|
1522 |
#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
|
|
|
1523 |
#$conf["timeout"]=array("10");
|
|
|
1524 |
#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
|
|
|
1525 |
#$conf["workingDir"]=array("path");
|
|
|
1526 |
#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
|
|
|
1527 |
#$conf["envs"]=array(array("key"=>"value"));
|
|
|
1528 |
#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
|
|
|
1529 |
#$conf["executeBy"]=array("bash");
|
|
|
1530 |
#參考資料:
|
|
|
1531 |
#https://www.php.net/manual/en/function.proc-open.php
|
|
|
1532 |
#https://www.php.net/manual/en/function.proc-get-status.php
|
|
|
1533 |
#https://www.php.net/manual/en/function.proc-terminate.php
|
|
|
1534 |
#備註:
|
|
|
1535 |
#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
|
|
|
1536 |
#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
|
|
|
1537 |
$proc=threads::proc($conf["threads::proc"]);
|
|
|
1538 |
unset($conf["threads::proc"]);
|
|
|
1539 |
|
|
|
1540 |
#如果執行異常
|
|
|
1541 |
if($proc["status"]==="false"){
|
|
|
1542 |
|
|
|
1543 |
#設置跳過,不適用
|
|
|
1544 |
$result["status"]="continue";
|
|
|
1545 |
|
|
|
1546 |
#回傳結果
|
|
|
1547 |
return $result;
|
|
|
1548 |
|
|
|
1549 |
}#if end
|
|
|
1550 |
|
|
|
1551 |
#函式說明:
|
|
|
1552 |
#更新透過proc執行的多程序資訊.
|
|
|
1553 |
#回傳結果:
|
|
|
1554 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1555 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1556 |
#$result["function"],當前執行的函式名稱.
|
|
|
1557 |
#$result["argu"],使用的參數.
|
|
|
1558 |
#$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"代表程序的資訊.
|
|
|
1559 |
#必填參數:
|
|
|
1560 |
#$conf["procs"],陣列,運行self::proc後回傳的content.
|
|
|
1561 |
$conf["threads::proc_update"]["procs"]=$procs["content"];
|
|
|
1562 |
#可省略參數:
|
|
|
1563 |
#無.
|
|
|
1564 |
#參考資料:
|
|
|
1565 |
#無.
|
|
|
1566 |
#備註:
|
|
|
1567 |
#無.
|
|
|
1568 |
$proc_update=threads::proc_update($conf["threads::proc_update"]);
|
|
|
1569 |
unset($conf["threads::proc_update"]);
|
|
|
1570 |
|
|
|
1571 |
#如果執行異常
|
|
|
1572 |
if($proc_update["status"]==="false"){
|
|
|
1573 |
|
|
|
1574 |
#設置跳過,不適用
|
|
|
1575 |
$result["status"]="continue";
|
|
|
1576 |
|
|
|
1577 |
#回傳結果
|
|
|
1578 |
return $result;
|
|
|
1579 |
|
|
|
1580 |
}#if end
|
|
|
1581 |
|
|
|
1582 |
#如果proc裡面的程式執行異常
|
|
|
1583 |
if($proc_update["content"][0]["status"]==="false"){
|
|
|
1584 |
|
|
|
1585 |
#設置跳過,不適用
|
|
|
1586 |
$result["status"]="continue";
|
|
|
1587 |
|
|
|
1588 |
#回傳結果
|
|
|
1589 |
return $result;
|
|
|
1590 |
|
|
|
1591 |
}#if end
|
|
|
1592 |
|
|
|
1593 |
#取得要儲存的php變數
|
|
|
1594 |
$value=$proc_update["content"][0];
|
|
|
1595 |
|
|
|
1596 |
#初始化要設置的列
|
|
|
1597 |
$row=array();
|
|
|
1598 |
|
|
|
1599 |
#設置存放的數值
|
|
|
1600 |
$row["value"]=$value;
|
|
|
1601 |
|
|
|
1602 |
#設置形態
|
| 368 |
liveuser |
1603 |
$row["type"]=$rdata["type"];
|
| 339 |
liveuser |
1604 |
|
|
|
1605 |
#若無設定 life
|
| 368 |
liveuser |
1606 |
if(!isset($rdata["life"])){
|
| 339 |
liveuser |
1607 |
|
|
|
1608 |
#設置預設的life
|
|
|
1609 |
$row["life"]=time()+$conf["info"]["defaultLifeTime"];
|
|
|
1610 |
|
|
|
1611 |
}#if end
|
|
|
1612 |
|
|
|
1613 |
#寫入資源
|
|
|
1614 |
$conf["info"]["resource"][$idInM]=$row;
|
|
|
1615 |
|
|
|
1616 |
#跳出 switch
|
|
|
1617 |
break;
|
|
|
1618 |
|
|
|
1619 |
#其他 type
|
|
|
1620 |
default:
|
|
|
1621 |
|
|
|
1622 |
#設置錯誤訊息
|
| 368 |
liveuser |
1623 |
$result["error"][]="unsupported type:".$rdata["type"];
|
| 339 |
liveuser |
1624 |
|
|
|
1625 |
#設置執行異常
|
|
|
1626 |
$result["status"]="false";
|
|
|
1627 |
|
|
|
1628 |
#回傳結果
|
|
|
1629 |
return $result;
|
|
|
1630 |
|
|
|
1631 |
}#switch end
|
|
|
1632 |
|
| 327 |
liveuser |
1633 |
}#if end
|
|
|
1634 |
|
|
|
1635 |
}#foreach end
|
|
|
1636 |
|
|
|
1637 |
#執行到這邊代表沒有符合條件的記錄
|
|
|
1638 |
|
|
|
1639 |
#設置結果為null
|
|
|
1640 |
$result["content"]=null;
|
|
|
1641 |
|
|
|
1642 |
#設置執行正常
|
|
|
1643 |
$result["status"]="true";
|
|
|
1644 |
|
|
|
1645 |
#回傳結果
|
|
|
1646 |
return $result;
|
|
|
1647 |
|
|
|
1648 |
#跳出 switch
|
|
|
1649 |
break;
|
|
|
1650 |
|
|
|
1651 |
#其他欄位
|
|
|
1652 |
default:
|
|
|
1653 |
|
|
|
1654 |
#設置錯誤訊息
|
|
|
1655 |
$result["error"][]="unsupported column:".$key;
|
|
|
1656 |
|
|
|
1657 |
#設置執行異常
|
|
|
1658 |
$result["status"]="false";
|
|
|
1659 |
|
|
|
1660 |
#回傳結果
|
|
|
1661 |
return $result;
|
|
|
1662 |
|
|
|
1663 |
}#switch end
|
| 339 |
liveuser |
1664 |
|
| 327 |
liveuser |
1665 |
}#foreach end
|
|
|
1666 |
|
|
|
1667 |
}#else end
|
|
|
1668 |
|
|
|
1669 |
#結束switch
|
|
|
1670 |
break;
|
|
|
1671 |
|
|
|
1672 |
#如果是 read
|
|
|
1673 |
case "read":
|
|
|
1674 |
|
|
|
1675 |
#如果是空的,亦即沒有條件,代表要取得全部.
|
| 368 |
liveuser |
1676 |
if(empty($rdata["condition"])){
|
| 327 |
liveuser |
1677 |
|
|
|
1678 |
#針對每筆記錄
|
|
|
1679 |
foreach($conf["info"]["resource"] as $idInM => $valInM){
|
|
|
1680 |
|
|
|
1681 |
#設置要取得的內容
|
| 339 |
liveuser |
1682 |
$result["content"][]=array("id"=>$idInM,"value"=>$valInM);
|
| 327 |
liveuser |
1683 |
|
|
|
1684 |
}#foreach end
|
|
|
1685 |
|
|
|
1686 |
#設置執行正常
|
|
|
1687 |
$result["status"]="true";
|
|
|
1688 |
|
|
|
1689 |
#回傳結果
|
|
|
1690 |
return $result;
|
|
|
1691 |
|
|
|
1692 |
}#if end
|
|
|
1693 |
|
|
|
1694 |
#反之有條件
|
|
|
1695 |
else{
|
|
|
1696 |
|
|
|
1697 |
#針對每個條件
|
| 368 |
liveuser |
1698 |
foreach($rdata["condition"] as $key => $val){
|
| 327 |
liveuser |
1699 |
|
|
|
1700 |
#判斷 $key
|
|
|
1701 |
switch($key){
|
|
|
1702 |
|
|
|
1703 |
#如果條件欄位是 id
|
|
|
1704 |
case "id":
|
|
|
1705 |
|
|
|
1706 |
#針對每筆記錄
|
|
|
1707 |
foreach($conf["info"]["resource"] as $idInM => $valInM){
|
|
|
1708 |
|
|
|
1709 |
#如果找到符合id的資料
|
|
|
1710 |
if($idInM===$val){
|
|
|
1711 |
|
|
|
1712 |
#設置結果
|
| 339 |
liveuser |
1713 |
$result["content"][]=array("id"=>$idInM,"value"=>$valInM);
|
| 327 |
liveuser |
1714 |
|
|
|
1715 |
#設置執行正常
|
|
|
1716 |
$result["status"]="true";
|
|
|
1717 |
|
|
|
1718 |
#回傳結果
|
|
|
1719 |
return $result;
|
|
|
1720 |
|
|
|
1721 |
}#if end
|
|
|
1722 |
|
|
|
1723 |
}#foreach end
|
|
|
1724 |
|
|
|
1725 |
#執行到這邊代表沒有符合條件的記錄
|
|
|
1726 |
|
|
|
1727 |
#設置結果為null
|
|
|
1728 |
$result["content"]=null;
|
|
|
1729 |
|
|
|
1730 |
#設置執行正常
|
|
|
1731 |
$result["status"]="true";
|
|
|
1732 |
|
|
|
1733 |
#回傳結果
|
|
|
1734 |
return $result;
|
|
|
1735 |
|
|
|
1736 |
#跳出 switch
|
|
|
1737 |
break;
|
|
|
1738 |
|
|
|
1739 |
#如果條件欄位是 value
|
|
|
1740 |
case "value":
|
|
|
1741 |
|
| 339 |
liveuser |
1742 |
#針對每筆記錄
|
| 327 |
liveuser |
1743 |
foreach($conf["info"]["resource"] as $idInM => $valInM){
|
|
|
1744 |
|
|
|
1745 |
#如果不是 php_variable
|
|
|
1746 |
if($valInM["type"]!=="php_variable"){
|
|
|
1747 |
|
|
|
1748 |
#跳過之
|
|
|
1749 |
continue;
|
|
|
1750 |
|
|
|
1751 |
}#if end
|
|
|
1752 |
|
|
|
1753 |
#如果找到符合value的資料
|
|
|
1754 |
if($valInM===$val){
|
|
|
1755 |
|
|
|
1756 |
#設置結果
|
| 339 |
liveuser |
1757 |
$result["content"]=array("id"=>$idInM,"value"=>$valInM);
|
| 327 |
liveuser |
1758 |
|
|
|
1759 |
#設置執行結果
|
|
|
1760 |
$result["status"]="true";
|
|
|
1761 |
|
|
|
1762 |
#回傳結果
|
|
|
1763 |
return $result;
|
|
|
1764 |
|
|
|
1765 |
}#if end
|
|
|
1766 |
|
|
|
1767 |
}#foreach end
|
|
|
1768 |
|
|
|
1769 |
#執行到這邊代表沒有符合條件的記錄
|
|
|
1770 |
|
|
|
1771 |
#設置結果為null
|
|
|
1772 |
$result["content"]=null;
|
|
|
1773 |
|
|
|
1774 |
#設置執行正常
|
|
|
1775 |
$result["status"]="true";
|
|
|
1776 |
|
|
|
1777 |
#回傳結果
|
|
|
1778 |
return $result;
|
|
|
1779 |
|
|
|
1780 |
#跳出 switch
|
|
|
1781 |
break;
|
|
|
1782 |
|
|
|
1783 |
#如果條件欄位是 pid
|
|
|
1784 |
case "pid":
|
|
|
1785 |
|
| 339 |
liveuser |
1786 |
#針對每筆記錄
|
| 327 |
liveuser |
1787 |
foreach($conf["info"]["resource"] as $idInM => $valInM){
|
|
|
1788 |
|
|
|
1789 |
#如果不是 proc
|
|
|
1790 |
if($valInM["type"]!=="proc"){
|
|
|
1791 |
|
|
|
1792 |
#跳過之
|
|
|
1793 |
continue;
|
|
|
1794 |
|
|
|
1795 |
}#if end
|
|
|
1796 |
|
|
|
1797 |
#取得 proc 的 pid
|
| 339 |
liveuser |
1798 |
$pidInM=$valInM["proc_get_status"]["pid"];
|
| 327 |
liveuser |
1799 |
|
|
|
1800 |
#如果找到符合value的資料
|
|
|
1801 |
if($pidInM===$val){
|
|
|
1802 |
|
|
|
1803 |
#設置結果
|
| 339 |
liveuser |
1804 |
$result["content"]=array("id"=>$idInM,"value"=>$valInM);
|
| 327 |
liveuser |
1805 |
|
|
|
1806 |
#設置執行結果
|
|
|
1807 |
$result["status"]="true";
|
|
|
1808 |
|
|
|
1809 |
#回傳結果
|
|
|
1810 |
return $result;
|
|
|
1811 |
|
|
|
1812 |
}#if end
|
|
|
1813 |
|
|
|
1814 |
}#foreach end
|
|
|
1815 |
|
|
|
1816 |
#執行到這邊代表沒有符合條件的記錄
|
|
|
1817 |
|
|
|
1818 |
#設置結果為null
|
|
|
1819 |
$result["content"]=null;
|
|
|
1820 |
|
|
|
1821 |
#設置執行正常
|
|
|
1822 |
$result["status"]="true";
|
|
|
1823 |
|
|
|
1824 |
#回傳結果
|
|
|
1825 |
return $result;
|
|
|
1826 |
|
|
|
1827 |
#跳出 switch
|
|
|
1828 |
break;
|
|
|
1829 |
|
|
|
1830 |
#其他欄位
|
|
|
1831 |
default:
|
|
|
1832 |
|
|
|
1833 |
#設置錯誤訊息
|
|
|
1834 |
$result["error"][]="unsupported column:".$key;
|
|
|
1835 |
|
|
|
1836 |
#設置執行異常
|
|
|
1837 |
$result["status"]="false";
|
|
|
1838 |
|
|
|
1839 |
#回傳結果
|
|
|
1840 |
return $result;
|
|
|
1841 |
|
|
|
1842 |
}#switch end
|
|
|
1843 |
|
|
|
1844 |
}#foreach end
|
|
|
1845 |
|
|
|
1846 |
}#else end
|
|
|
1847 |
|
|
|
1848 |
#結束switch
|
|
|
1849 |
break;
|
|
|
1850 |
|
|
|
1851 |
#其他 action
|
|
|
1852 |
default:
|
|
|
1853 |
|
|
|
1854 |
#設置錯誤訊息
|
|
|
1855 |
$result["error"][]="unsupported action:".$conf["request"]["action"];
|
|
|
1856 |
|
|
|
1857 |
#設置執行異常
|
|
|
1858 |
$result["status"]="false";
|
|
|
1859 |
|
|
|
1860 |
#回傳結果
|
|
|
1861 |
return $result;
|
|
|
1862 |
|
|
|
1863 |
}#switch end
|
|
|
1864 |
|
|
|
1865 |
#執行到這邊代表不適用
|
|
|
1866 |
|
|
|
1867 |
#設置不適用,可跳過
|
|
|
1868 |
$result["status"]="continue";
|
| 306 |
liveuser |
1869 |
|
| 327 |
liveuser |
1870 |
#回傳結果
|
|
|
1871 |
return $result;
|
|
|
1872 |
|
|
|
1873 |
}#function addOnProcessFunc end
|
| 306 |
liveuser |
1874 |
|
| 327 |
liveuser |
1875 |
/*
|
|
|
1876 |
#函式說明:
|
|
|
1877 |
#用於 server 的 funcToRunWhenIdle,亦即沒有收到訊息閒置時要做什麼事情.
|
|
|
1878 |
#回傳結果:
|
|
|
1879 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1880 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1881 |
#$result["function"],當前執行的函式名稱.
|
|
|
1882 |
#必填參數:
|
|
|
1883 |
#$conf["info"],陣列,資料庫資訊.
|
|
|
1884 |
$conf["info"]=array();
|
| 339 |
liveuser |
1885 |
#$conf["client"],陣列,每個用戶的socket.
|
|
|
1886 |
$conf["client"]="";
|
|
|
1887 |
#$conf["serverCache"],陣列,只有server可以看到的cache.
|
|
|
1888 |
$conf["serverCache"]=array();
|
| 327 |
liveuser |
1889 |
#$conf["clientCache"],陣列,給予所有用戶的cache.
|
|
|
1890 |
$conf["clientCache"]=array();
|
|
|
1891 |
#可省略參數:
|
|
|
1892 |
#無.
|
|
|
1893 |
#參考資料:
|
|
|
1894 |
#無.
|
|
|
1895 |
#備註:
|
|
|
1896 |
#無.
|
|
|
1897 |
*/
|
|
|
1898 |
public static function funcToRunWhenIdle(&$conf){
|
|
|
1899 |
|
| 339 |
liveuser |
1900 |
#初始化要回傳的結果
|
|
|
1901 |
$result=array();
|
|
|
1902 |
|
|
|
1903 |
#取得當前執行的函數名稱
|
|
|
1904 |
$result["function"]=__FUNCTION__;
|
|
|
1905 |
|
|
|
1906 |
#如果沒有參數
|
|
|
1907 |
if(func_num_args()==0){
|
|
|
1908 |
|
|
|
1909 |
#設置執行失敗
|
|
|
1910 |
$result["status"]="false";
|
|
|
1911 |
|
|
|
1912 |
#設置執行錯誤訊息
|
|
|
1913 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
1914 |
|
|
|
1915 |
#回傳結果
|
|
|
1916 |
return $result;
|
|
|
1917 |
|
|
|
1918 |
}#if end
|
|
|
1919 |
|
|
|
1920 |
#涵式說明:
|
|
|
1921 |
#判斷當前環境為web還是cmd
|
|
|
1922 |
#回傳結果:
|
|
|
1923 |
#$result,"web"或"cmd"
|
|
|
1924 |
if(csInformation::getEnv()==="web"){
|
|
|
1925 |
|
|
|
1926 |
#設置執行失敗
|
|
|
1927 |
$result["status"]="false";
|
|
|
1928 |
|
|
|
1929 |
#設置執行錯誤訊息
|
|
|
1930 |
$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
|
|
|
1931 |
|
|
|
1932 |
#回傳結果
|
|
|
1933 |
return $result;
|
|
|
1934 |
|
|
|
1935 |
}#if end
|
| 327 |
liveuser |
1936 |
|
| 339 |
liveuser |
1937 |
#取得參數
|
|
|
1938 |
$result["argu"]=$conf;
|
|
|
1939 |
|
|
|
1940 |
#如果 $conf 不為陣列
|
|
|
1941 |
if(gettype($conf)!=="array"){
|
|
|
1942 |
|
|
|
1943 |
#設置執行失敗
|
|
|
1944 |
$result["status"]="false";
|
|
|
1945 |
|
|
|
1946 |
#設置執行錯誤訊息
|
|
|
1947 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1948 |
|
|
|
1949 |
#如果傳入的參數為 null
|
|
|
1950 |
if(is_null($conf)){
|
|
|
1951 |
|
|
|
1952 |
#設置執行錯誤訊息
|
|
|
1953 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1954 |
|
|
|
1955 |
}#if end
|
|
|
1956 |
|
|
|
1957 |
#回傳結果
|
|
|
1958 |
return $result;
|
|
|
1959 |
|
|
|
1960 |
}#if end
|
|
|
1961 |
|
|
|
1962 |
#檢查參數
|
|
|
1963 |
#函式說明:
|
|
|
1964 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
1965 |
#回傳結果:
|
|
|
1966 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1967 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
1968 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
1969 |
#$result["function"],當前執行的函式名稱.
|
|
|
1970 |
#$result["argu"],設置給予的參數.
|
|
|
1971 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1972 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1973 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1974 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1975 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1976 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1977 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1978 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1979 |
#必填參數:
|
|
|
1980 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1981 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1982 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1983 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1984 |
#可省略參數:
|
|
|
1985 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1986 |
#$conf["mustBeFilledVariableName"]=array();
|
|
|
1987 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
|
|
1988 |
#$conf["mustBeFilledVariableType"]=array();
|
|
|
1989 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1990 |
#$conf["canBeEmptyString"]="false";
|
|
|
1991 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1992 |
#$conf["canNotBeEmpty"]=array();
|
|
|
1993 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1994 |
#$conf["canBeEmpty"]=array();
|
|
|
1995 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
| 340 |
liveuser |
1996 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("info","serverCache","clientCache");
|
| 339 |
liveuser |
1997 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1998 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("info","client","serverCache","clientCache");
|
|
|
1999 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2000 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("info","client","serverCache","clientCache");
|
|
|
2001 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2002 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($sock);
|
|
|
2003 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
2004 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
2005 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
2006 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
2007 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
2008 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
2009 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2010 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2011 |
#參考資料:
|
|
|
2012 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2013 |
#備註:
|
|
|
2014 |
#無.
|
|
|
2015 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2016 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2017 |
|
|
|
2018 |
#如果執行異常
|
|
|
2019 |
if($checkArguments["status"]==="false"){
|
|
|
2020 |
|
|
|
2021 |
#設置執行異常識別
|
|
|
2022 |
$result["status"]="false";
|
|
|
2023 |
|
|
|
2024 |
#設置執行錯誤
|
|
|
2025 |
$result["error"]=$checkArguments;
|
|
|
2026 |
|
|
|
2027 |
#回傳結果
|
|
|
2028 |
return $result;
|
|
|
2029 |
|
|
|
2030 |
}#if end
|
|
|
2031 |
|
|
|
2032 |
#如果檢查不通過
|
|
|
2033 |
if($checkArguments["passed"]==="false"){
|
|
|
2034 |
|
|
|
2035 |
#設置執行異常識別
|
|
|
2036 |
$result["status"]="false";
|
|
|
2037 |
|
|
|
2038 |
#設置執行錯誤
|
|
|
2039 |
$result["error"]=$checkArguments;
|
|
|
2040 |
|
|
|
2041 |
#回傳結果
|
|
|
2042 |
return $result;
|
|
|
2043 |
|
|
|
2044 |
}#if end
|
|
|
2045 |
|
|
|
2046 |
#取得resouce的參考
|
|
|
2047 |
$resource=&$conf["info"]["resource"];
|
|
|
2048 |
|
|
|
2049 |
#針對每個資源
|
|
|
2050 |
foreach($resource as $rid => $info){
|
|
|
2051 |
|
|
|
2052 |
#檢查參數
|
|
|
2053 |
#函式說明:
|
|
|
2054 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
2055 |
#回傳結果:
|
|
|
2056 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2057 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
2058 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
2059 |
#$result["function"],當前執行的函式名稱.
|
|
|
2060 |
#$result["argu"],設置給予的參數.
|
|
|
2061 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2062 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2063 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2064 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2065 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
2066 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2067 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2068 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2069 |
#必填參數:
|
|
|
2070 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2071 |
$conf["variableCheck::checkArguments"]["varInput"]=$info;
|
|
|
2072 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2073 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2074 |
#可省略參數:
|
|
|
2075 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2076 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("value","type","life");
|
|
|
2077 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
| 383 |
liveuser |
2078 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array(null,"string","integer");
|
| 339 |
liveuser |
2079 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2080 |
#$conf["canBeEmptyString"]="false";
|
|
|
2081 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
2082 |
#$conf["canNotBeEmpty"]=array();
|
|
|
2083 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
2084 |
#$conf["canBeEmpty"]=array();
|
|
|
2085 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
2086 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("action");
|
|
|
2087 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2088 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("condition","value","type");
|
|
|
2089 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2090 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array",null,"string");
|
|
|
2091 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2092 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array(),null,null);
|
|
|
2093 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
2094 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
2095 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
2096 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
2097 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
2098 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
2099 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2100 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2101 |
#參考資料:
|
|
|
2102 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2103 |
#備註:
|
|
|
2104 |
#無.
|
|
|
2105 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2106 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2107 |
|
|
|
2108 |
#如果執行異常
|
|
|
2109 |
if($checkArguments["status"]==="false"){
|
|
|
2110 |
|
|
|
2111 |
#設置執行異常識別
|
|
|
2112 |
$result["status"]="false";
|
|
|
2113 |
|
|
|
2114 |
#設置執行錯誤
|
|
|
2115 |
$result["error"]=$checkArguments;
|
|
|
2116 |
|
|
|
2117 |
#回傳結果
|
|
|
2118 |
return $result;
|
|
|
2119 |
|
|
|
2120 |
}#if end
|
|
|
2121 |
|
|
|
2122 |
#如果檢查不通過
|
|
|
2123 |
if($checkArguments["passed"]==="false"){
|
|
|
2124 |
|
|
|
2125 |
#設置執行異常識別
|
|
|
2126 |
$result["status"]="false";
|
|
|
2127 |
|
|
|
2128 |
#設置執行錯誤
|
|
|
2129 |
$result["error"]=$checkArguments;
|
|
|
2130 |
|
|
|
2131 |
#回傳結果
|
|
|
2132 |
return $result;
|
|
|
2133 |
|
|
|
2134 |
}#if end
|
|
|
2135 |
|
|
|
2136 |
#如果 life 過期
|
|
|
2137 |
if(time()>$info["life"]){
|
|
|
2138 |
|
|
|
2139 |
#如果是 php_variable 的資源
|
|
|
2140 |
if($info["type"]==="php_variable"){
|
|
|
2141 |
|
|
|
2142 |
#移除之
|
|
|
2143 |
unset($resource[$rid]);
|
|
|
2144 |
|
|
|
2145 |
}#if end
|
|
|
2146 |
|
|
|
2147 |
#反之如果是 proc 的自選
|
|
|
2148 |
else if($info["type"]==="proc"){
|
|
|
2149 |
|
|
|
2150 |
#關閉之
|
|
|
2151 |
proc_close($info["value"]);
|
|
|
2152 |
|
|
|
2153 |
#移除之
|
|
|
2154 |
unset($resource[$rid]);
|
|
|
2155 |
|
|
|
2156 |
}#if end
|
|
|
2157 |
|
|
|
2158 |
#反之為不應該有的類型
|
|
|
2159 |
else{
|
|
|
2160 |
|
|
|
2161 |
#設置執行異常識別
|
|
|
2162 |
$result["status"]="false";
|
|
|
2163 |
|
|
|
2164 |
#設置執行錯誤
|
|
|
2165 |
$result["error"][]="invalid resource type:".$info["type"];
|
|
|
2166 |
|
|
|
2167 |
#設置執行錯誤
|
|
|
2168 |
$result["error"][]=$info;
|
|
|
2169 |
|
|
|
2170 |
#回傳結果
|
|
|
2171 |
return $result;
|
|
|
2172 |
|
|
|
2173 |
}#else end
|
|
|
2174 |
|
|
|
2175 |
}#if end
|
|
|
2176 |
|
|
|
2177 |
}#foreach end
|
|
|
2178 |
|
|
|
2179 |
#設置執行正常
|
|
|
2180 |
$result["status"]="true";
|
| 327 |
liveuser |
2181 |
|
| 339 |
liveuser |
2182 |
#回傳結果
|
|
|
2183 |
return $result;
|
|
|
2184 |
|
|
|
2185 |
}#function funcToRunWhenIdle end
|
|
|
2186 |
|
|
|
2187 |
/*
|
|
|
2188 |
#函式說明:
|
|
|
2189 |
#給 server 結束前呼叫的 callback 函式.
|
|
|
2190 |
#回傳結果:
|
|
|
2191 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2192 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2193 |
#$result["function"],當前執行的函式名稱.
|
|
|
2194 |
#必填參數:
|
|
|
2195 |
#$conf["info"],陣列,資料庫資訊.
|
|
|
2196 |
$conf["info"]=array();
|
|
|
2197 |
#$conf["serverCache"],陣列,只有server可以看到的cache.
|
|
|
2198 |
$conf["serverCache"]=array();
|
|
|
2199 |
#$conf["clientCache"],陣列,給予所有用戶的cache.
|
|
|
2200 |
$conf["clientCache"]=array();
|
|
|
2201 |
#可省略參數:
|
|
|
2202 |
#無.
|
|
|
2203 |
#參考資料:
|
|
|
2204 |
#無.
|
|
|
2205 |
#備註:
|
|
|
2206 |
#無.
|
|
|
2207 |
*/
|
|
|
2208 |
public static function closeAllResurce(&$conf){
|
|
|
2209 |
|
|
|
2210 |
#初始化要回傳的結果
|
|
|
2211 |
$result=array();
|
| 327 |
liveuser |
2212 |
|
| 339 |
liveuser |
2213 |
#取得當前執行的函數名稱
|
|
|
2214 |
$result["function"]=__FUNCTION__;
|
|
|
2215 |
|
|
|
2216 |
#如果沒有參數
|
|
|
2217 |
if(func_num_args()==0){
|
|
|
2218 |
|
|
|
2219 |
#設置執行失敗
|
|
|
2220 |
$result["status"]="false";
|
|
|
2221 |
|
|
|
2222 |
#設置執行錯誤訊息
|
|
|
2223 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
2224 |
|
|
|
2225 |
#回傳結果
|
|
|
2226 |
return $result;
|
|
|
2227 |
|
|
|
2228 |
}#if end
|
|
|
2229 |
|
|
|
2230 |
#涵式說明:
|
|
|
2231 |
#判斷當前環境為web還是cmd
|
|
|
2232 |
#回傳結果:
|
|
|
2233 |
#$result,"web"或"cmd"
|
|
|
2234 |
if(csInformation::getEnv()==="web"){
|
|
|
2235 |
|
|
|
2236 |
#設置執行失敗
|
|
|
2237 |
$result["status"]="false";
|
|
|
2238 |
|
|
|
2239 |
#設置執行錯誤訊息
|
|
|
2240 |
$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
|
|
|
2241 |
|
|
|
2242 |
#回傳結果
|
|
|
2243 |
return $result;
|
|
|
2244 |
|
|
|
2245 |
}#if end
|
|
|
2246 |
|
|
|
2247 |
#取得參數
|
|
|
2248 |
$result["argu"]=$conf;
|
|
|
2249 |
|
|
|
2250 |
#如果 $conf 不為陣列
|
|
|
2251 |
if(gettype($conf)!=="array"){
|
|
|
2252 |
|
|
|
2253 |
#設置執行失敗
|
|
|
2254 |
$result["status"]="false";
|
|
|
2255 |
|
|
|
2256 |
#設置執行錯誤訊息
|
|
|
2257 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2258 |
|
|
|
2259 |
#如果傳入的參數為 null
|
|
|
2260 |
if(is_null($conf)){
|
|
|
2261 |
|
|
|
2262 |
#設置執行錯誤訊息
|
|
|
2263 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2264 |
|
|
|
2265 |
}#if end
|
|
|
2266 |
|
|
|
2267 |
#回傳結果
|
|
|
2268 |
return $result;
|
|
|
2269 |
|
|
|
2270 |
}#if end
|
|
|
2271 |
|
|
|
2272 |
#檢查參數
|
|
|
2273 |
#函式說明:
|
|
|
2274 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
2275 |
#回傳結果:
|
|
|
2276 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2277 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
2278 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
2279 |
#$result["function"],當前執行的函式名稱.
|
|
|
2280 |
#$result["argu"],設置給予的參數.
|
|
|
2281 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2282 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2283 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2284 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2285 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
2286 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2287 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2288 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2289 |
#必填參數:
|
|
|
2290 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2291 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2292 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2293 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2294 |
#可省略參數:
|
|
|
2295 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2296 |
#$conf["mustBeFilledVariableName"]=array();
|
|
|
2297 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
|
|
2298 |
#$conf["mustBeFilledVariableType"]=array();
|
|
|
2299 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2300 |
#$conf["canBeEmptyString"]="false";
|
|
|
2301 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
2302 |
#$conf["canNotBeEmpty"]=array();
|
|
|
2303 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
2304 |
#$conf["canBeEmpty"]=array();
|
|
|
2305 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
2306 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("serverCache","clientCache");
|
|
|
2307 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2308 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("info","serverCache","clientCache");
|
|
|
2309 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2310 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","array");
|
|
|
2311 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2312 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($sock);
|
|
|
2313 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
2314 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
2315 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
2316 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
2317 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
2318 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
2319 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2320 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2321 |
#參考資料:
|
|
|
2322 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2323 |
#備註:
|
|
|
2324 |
#無.
|
|
|
2325 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2326 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2327 |
|
|
|
2328 |
#如果執行異常
|
|
|
2329 |
if($checkArguments["status"]==="false"){
|
|
|
2330 |
|
|
|
2331 |
#設置執行異常識別
|
|
|
2332 |
$result["status"]="false";
|
|
|
2333 |
|
|
|
2334 |
#設置執行錯誤
|
|
|
2335 |
$result["error"]=$checkArguments;
|
|
|
2336 |
|
|
|
2337 |
#回傳結果
|
|
|
2338 |
return $result;
|
|
|
2339 |
|
|
|
2340 |
}#if end
|
|
|
2341 |
|
|
|
2342 |
#如果檢查不通過
|
|
|
2343 |
if($checkArguments["passed"]==="false"){
|
|
|
2344 |
|
|
|
2345 |
#設置執行異常識別
|
|
|
2346 |
$result["status"]="false";
|
|
|
2347 |
|
|
|
2348 |
#設置執行錯誤
|
|
|
2349 |
$result["error"]=$checkArguments;
|
|
|
2350 |
|
|
|
2351 |
#回傳結果
|
|
|
2352 |
return $result;
|
|
|
2353 |
|
|
|
2354 |
}#if end
|
|
|
2355 |
|
|
|
2356 |
#針對每個資源
|
|
|
2357 |
foreach($conf["info"]["resouce"] as $id => $resource){
|
|
|
2358 |
|
|
|
2359 |
#如果是 proc 類型
|
|
|
2360 |
if($resource["type"]==="proc"){
|
|
|
2361 |
|
|
|
2362 |
#proc_close資源,避免系統出錯
|
|
|
2363 |
proc_close($resource["value"]);
|
|
|
2364 |
|
|
|
2365 |
}#if end
|
|
|
2366 |
|
|
|
2367 |
}#foreach end
|
|
|
2368 |
|
|
|
2369 |
}#function closeAllResurce end
|
| 341 |
liveuser |
2370 |
|
|
|
2371 |
/*
|
|
|
2372 |
#函式說明:
|
|
|
2373 |
#存取快取服務.
|
|
|
2374 |
#回傳結果:
|
|
|
2375 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2376 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2377 |
#$result["function"],當前執行的函式名稱.
|
|
|
2378 |
#$result["argu"],所使用的參數.
|
|
|
2379 |
#$result["content"],得到的回應字串.
|
|
|
2380 |
#必填參數:
|
|
|
2381 |
#$conf["action"],字串,"read":代表要讀取資料;"write":代表要寫入資料.
|
|
|
2382 |
#$conf["action"]="";
|
|
|
2383 |
#$conf["type"],字串,"php_variable":php的變數;"proc",透過proc運行的程序,可透過標準輸入進行操作.
|
|
|
2384 |
#$conf["type"]="";
|
|
|
2385 |
#可省略參數:
|
|
|
2386 |
#$conf["value"],null,"action"參數為write時,資源的內容,形態不固定.
|
|
|
2387 |
#$conf["value"]=null;
|
|
|
2388 |
#$conf["sock"],字串,unix domain socket的路徑與名稱,預設為相對於當前套件的 var/qbpwcf/resource.sock
|
|
|
2389 |
#$conf["sock"]="";
|
|
|
2390 |
#$conf["condition"],陣列,條件,預設為空陣列,代表沒有條件,通常是為新增資源,元素的key為"id"者代表目標資源的id;元素的key為"value"者代表目標資源是否相等於"value",且"type"為"php_variable";元素的key為"pid"者代表運行的資源程序pid,且"type"為"proc"
|
|
|
2391 |
#$conf["condition"]=array();
|
|
|
2392 |
#參考資料:
|
|
|
2393 |
#無.
|
|
|
2394 |
#備註:
|
|
|
2395 |
#僅能在命令列環境下運行.
|
| 383 |
liveuser |
2396 |
#若於proc中運行,則不會因為無法存取socket而報錯並結束執行.
|
| 341 |
liveuser |
2397 |
*/
|
|
|
2398 |
public static function client(&$conf){
|
|
|
2399 |
|
|
|
2400 |
#初始化要回傳的結果
|
|
|
2401 |
$result=array();
|
| 339 |
liveuser |
2402 |
|
| 341 |
liveuser |
2403 |
#取得當前執行的函數名稱
|
|
|
2404 |
$result["function"]=__FUNCTION__;
|
|
|
2405 |
|
|
|
2406 |
#如果沒有參數
|
|
|
2407 |
if(func_num_args()==0){
|
|
|
2408 |
|
|
|
2409 |
#設置執行失敗
|
|
|
2410 |
$result["status"]="false";
|
|
|
2411 |
|
|
|
2412 |
#設置執行錯誤訊息
|
|
|
2413 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
2414 |
|
|
|
2415 |
#回傳結果
|
|
|
2416 |
return $result;
|
|
|
2417 |
|
|
|
2418 |
}#if end
|
|
|
2419 |
|
|
|
2420 |
#涵式說明:
|
|
|
2421 |
#判斷當前環境為web還是cmd
|
|
|
2422 |
#回傳結果:
|
|
|
2423 |
#$result,"web"或"cmd"
|
|
|
2424 |
if(csInformation::getEnv()==="web"){
|
|
|
2425 |
|
|
|
2426 |
#設置執行失敗
|
|
|
2427 |
$result["status"]="false";
|
|
|
2428 |
|
|
|
2429 |
#設置執行錯誤訊息
|
|
|
2430 |
$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
|
|
|
2431 |
|
|
|
2432 |
#回傳結果
|
|
|
2433 |
return $result;
|
|
|
2434 |
|
|
|
2435 |
}#if end
|
|
|
2436 |
|
|
|
2437 |
#取得參數
|
|
|
2438 |
$result["argu"]=$conf;
|
|
|
2439 |
|
|
|
2440 |
#如果 $conf 不為陣列
|
|
|
2441 |
if(gettype($conf)!=="array"){
|
|
|
2442 |
|
|
|
2443 |
#設置執行失敗
|
|
|
2444 |
$result["status"]="false";
|
|
|
2445 |
|
|
|
2446 |
#設置執行錯誤訊息
|
|
|
2447 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2448 |
|
|
|
2449 |
#如果傳入的參數為 null
|
|
|
2450 |
if(is_null($conf)){
|
|
|
2451 |
|
|
|
2452 |
#設置執行錯誤訊息
|
|
|
2453 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2454 |
|
|
|
2455 |
}#if end
|
|
|
2456 |
|
|
|
2457 |
#回傳結果
|
|
|
2458 |
return $result;
|
|
|
2459 |
|
|
|
2460 |
}#if end
|
|
|
2461 |
|
|
|
2462 |
#預設的 unix domain socket addr
|
|
|
2463 |
$sock=pathinfo(__FILE__)["dirname"]."/../../var/qbpwcf/resource.sock";
|
|
|
2464 |
|
|
|
2465 |
#檢查參數
|
|
|
2466 |
#函式說明:
|
|
|
2467 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
2468 |
#回傳結果:
|
|
|
2469 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2470 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
2471 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
2472 |
#$result["function"],當前執行的函式名稱.
|
|
|
2473 |
#$result["argu"],設置給予的參數.
|
|
|
2474 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2475 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2476 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2477 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2478 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
2479 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2480 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2481 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2482 |
#必填參數:
|
|
|
2483 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2484 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2485 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2486 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2487 |
#可省略參數:
|
|
|
2488 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2489 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("action","type");
|
|
|
2490 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
|
|
2491 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
2492 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2493 |
#$conf["canBeEmptyString"]="false";
|
|
|
2494 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
2495 |
#$conf["canNotBeEmpty"]=array();
|
|
|
2496 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
2497 |
#$conf["canBeEmpty"]=array();
|
|
|
2498 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
2499 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sock");
|
|
|
2500 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2501 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("value","sock","condition");
|
|
|
2502 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2503 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array(null,"string","array");
|
|
|
2504 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2505 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,$sock,array());
|
|
|
2506 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
2507 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
2508 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
2509 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
2510 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
2511 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
2512 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2513 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2514 |
#參考資料:
|
|
|
2515 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2516 |
#備註:
|
|
|
2517 |
#無.
|
|
|
2518 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2519 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2520 |
|
|
|
2521 |
#如果執行異常
|
|
|
2522 |
if($checkArguments["status"]==="false"){
|
|
|
2523 |
|
|
|
2524 |
#設置執行異常識別
|
|
|
2525 |
$result["status"]="false";
|
|
|
2526 |
|
|
|
2527 |
#設置執行錯誤
|
|
|
2528 |
$result["error"]=$checkArguments;
|
|
|
2529 |
|
|
|
2530 |
#回傳結果
|
|
|
2531 |
return $result;
|
|
|
2532 |
|
|
|
2533 |
}#if end
|
|
|
2534 |
|
|
|
2535 |
#如果檢查不通過
|
|
|
2536 |
if($checkArguments["passed"]==="false"){
|
|
|
2537 |
|
|
|
2538 |
#設置執行異常識別
|
|
|
2539 |
$result["status"]="false";
|
|
|
2540 |
|
|
|
2541 |
#設置執行錯誤
|
|
|
2542 |
$result["error"]=$checkArguments;
|
|
|
2543 |
|
|
|
2544 |
#回傳結果
|
|
|
2545 |
return $result;
|
|
|
2546 |
|
|
|
2547 |
}#if end
|
|
|
2548 |
|
|
|
2549 |
#初始化要傳遞的內容
|
|
|
2550 |
$request=array();
|
|
|
2551 |
|
| 368 |
liveuser |
2552 |
#設置要傳送的 data
|
|
|
2553 |
$request["data"]["action"]=$conf["action"];
|
| 341 |
liveuser |
2554 |
|
| 368 |
liveuser |
2555 |
#設置要傳送的 type
|
|
|
2556 |
$request["data"]["type"]=$conf["type"];
|
| 341 |
liveuser |
2557 |
|
| 368 |
liveuser |
2558 |
#設置condition
|
|
|
2559 |
$request["data"]["condition"]=$conf["condition"];
|
|
|
2560 |
|
|
|
2561 |
#如果有 value
|
| 341 |
liveuser |
2562 |
if(isset($conf["value"])){
|
|
|
2563 |
|
| 368 |
liveuser |
2564 |
#設置 value
|
|
|
2565 |
$request["data"]["value"]=$conf["value"];
|
| 341 |
liveuser |
2566 |
|
|
|
2567 |
}#if end
|
|
|
2568 |
|
|
|
2569 |
#連線到 unix domain socket,傳遞訊息,取得回應.
|
|
|
2570 |
#連線到 sock::unixDomainSocketServer 產生的 unix domain socket,傳送指定的訊息.
|
|
|
2571 |
#回傳結果:
|
|
|
2572 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
2573 |
#$result["error"],錯誤訊息陣列.
|
|
|
2574 |
#$result["function"],當前執行的函式名稱.
|
|
|
2575 |
#$result["argu"],使用的參數.
|
|
|
2576 |
#$result["content"],得到的回應.
|
|
|
2577 |
#必填參數:
|
|
|
2578 |
#$conf["msg"],陣列,要傳送的訊息,其主$conf["msg"]["id"],是無法指定的.
|
|
|
2579 |
$conf["sock::sendAnyMsgToQBPWCFunixSocket"]["msg"]=$request;
|
|
|
2580 |
#可省略參數:
|
|
|
2581 |
#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
|
|
|
2582 |
$conf["sock::sendAnyMsgToQBPWCFunixSocket"]["sock"]=$conf["sock"];
|
|
|
2583 |
#參考資料:
|
|
|
2584 |
#無.
|
|
|
2585 |
#備註:
|
|
|
2586 |
#無.
|
|
|
2587 |
$sendAnyMsgToQBPWCFunixSocket=sock::sendAnyMsgToQBPWCFunixSocket($conf["sock::sendAnyMsgToQBPWCFunixSocket"]);
|
|
|
2588 |
unset($conf["sock::sendAnyMsgToQBPWCFunixSocket"]);
|
|
|
2589 |
|
|
|
2590 |
#如果執行異常
|
|
|
2591 |
if($sendAnyMsgToQBPWCFunixSocket["status"]==="false"){
|
|
|
2592 |
|
|
|
2593 |
#設置執行異常識別
|
|
|
2594 |
$result["status"]="false";
|
|
|
2595 |
|
|
|
2596 |
#設置執行錯誤
|
|
|
2597 |
$result["error"]=$sendAnyMsgToQBPWCFunixSocket;
|
|
|
2598 |
|
|
|
2599 |
#回傳結果
|
|
|
2600 |
return $result;
|
|
|
2601 |
|
|
|
2602 |
}#if end
|
|
|
2603 |
|
|
|
2604 |
#設置得到的回應
|
|
|
2605 |
$result["content"]=$sendAnyMsgToQBPWCFunixSocket["content"];
|
|
|
2606 |
|
|
|
2607 |
#設置執行正常
|
|
|
2608 |
$result["status"]="true";
|
|
|
2609 |
|
|
|
2610 |
#回傳結果
|
|
|
2611 |
return $result;
|
|
|
2612 |
|
|
|
2613 |
}#function client end
|
|
|
2614 |
|
| 327 |
liveuser |
2615 |
}#classs refedosource end
|