| 11 |
liveuser |
1 |
#!/usr/bin/php
|
|
|
2 |
<?php
|
|
|
3 |
|
|
|
4 |
/*
|
|
|
5 |
|
|
|
6 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 226 |
liveuser |
7 |
Copyright (C) 2014~2025 MIN ZHI, CHEN
|
| 11 |
liveuser |
8 |
|
|
|
9 |
This file is part of QBPWCF.
|
|
|
10 |
|
|
|
11 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
12 |
it under the terms of the GNU General Public License as published by
|
|
|
13 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
14 |
(at your option) any later version.
|
|
|
15 |
|
|
|
16 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
17 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
18 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
19 |
GNU General Public License for more details.
|
|
|
20 |
|
|
|
21 |
You should have received a copy of the GNU General Public License
|
|
|
22 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
23 |
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
#使用命名空間qbpwcf
|
|
|
27 |
namespace qbpwcf;
|
|
|
28 |
|
|
|
29 |
#初始化輸出
|
|
|
30 |
$output=array();
|
|
|
31 |
|
|
|
32 |
#取得 lib path
|
| 99 |
liveuser |
33 |
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../../../usr/bin/libexec/folderOfUsrLib.php"),$output,$status);
|
| 11 |
liveuser |
34 |
|
|
|
35 |
#如果執行失敗
|
|
|
36 |
if($status!==0){
|
|
|
37 |
|
|
|
38 |
#debug
|
|
|
39 |
var_dump(__LINE__,$output);
|
|
|
40 |
|
|
|
41 |
#結束執行,回傳shell 1.
|
|
|
42 |
exit(1);
|
|
|
43 |
|
|
|
44 |
}#if end
|
|
|
45 |
|
|
|
46 |
#儲存lib path
|
|
|
47 |
$folderOfUsrLib=$output[0];
|
|
|
48 |
|
|
|
49 |
#初始化輸出
|
|
|
50 |
$output=array();
|
|
|
51 |
|
|
|
52 |
#以該檔案的實際位置的 lib path 為 include path 首位
|
| 99 |
liveuser |
53 |
exec("cd ".pathinfo(__FILE__)["dirname"]."/../../../../usr/".$folderOfUsrLib."/qbpwcf;pwd;",$output,$status);
|
| 11 |
liveuser |
54 |
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
|
|
|
55 |
|
|
|
56 |
#匯入套件
|
|
|
57 |
require_once("allInOne.php");
|
|
|
58 |
|
|
|
59 |
#建議的log位置
|
|
|
60 |
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";
|
|
|
61 |
|
|
|
62 |
#./usr_bin_test.php --cmd configCache.php
|
|
|
63 |
|
|
|
64 |
#函式說明:
|
|
|
65 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
66 |
#回傳結果:
|
|
|
67 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
68 |
#$result["error"],錯誤訊息陣列.
|
|
|
69 |
#$result["function"],當前執行的函數名稱.
|
|
|
70 |
#$result["argu"],使用的參數.
|
|
|
71 |
#$result["cmd"],執行的指令內容.
|
|
|
72 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
73 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
74 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
75 |
#$result["running"],是否還在執行.
|
|
|
76 |
#$result["pid"],pid.
|
|
|
77 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
78 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
79 |
#必填參數:
|
|
|
80 |
#$conf["command"],字串,要執行的指令.
|
|
|
81 |
$conf["command"]="./usr_bin_test.php";
|
|
|
82 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
83 |
$conf["fileArgu"]=__FILE__;
|
|
|
84 |
#可省略參數:
|
|
|
85 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
86 |
$conf["argu"]=array("--cmd","configCache.php");
|
|
|
87 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
88 |
#$conf["arguIsAddr"]=array();
|
|
|
89 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
90 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
91 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
92 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
93 |
#$conf["enablePrintDescription"]="true";
|
|
|
94 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
95 |
#$conf["printDescription"]="";
|
|
|
96 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
97 |
$conf["escapeshellarg"]="true";
|
|
|
98 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
99 |
#$conf["thereIsShellVar"]=array();
|
|
|
100 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
101 |
#$conf["username"]="";
|
|
|
102 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
103 |
#$conf["password"]="";
|
|
|
104 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
105 |
#$conf["useScript"]="";
|
|
|
106 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
107 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
108 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
109 |
#$conf["inBackGround"]="";
|
|
|
110 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
111 |
#$conf["getErr"]="false";
|
|
|
112 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
113 |
$conf["doNotRun"]="true";
|
|
|
114 |
#參考資料:
|
|
|
115 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
116 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
117 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
118 |
#備註:
|
|
|
119 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
120 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
121 |
$callShell=external::callShell($conf);
|
|
|
122 |
unset($conf);
|
|
|
123 |
|
|
|
124 |
#如果執行失敗
|
|
|
125 |
if($callShell["status"]==="false"){
|
|
|
126 |
|
|
|
127 |
#debug
|
|
|
128 |
var_dump($callShell);
|
|
|
129 |
|
|
|
130 |
#結束執行,回傳1給shell.
|
|
|
131 |
exit(1);
|
|
|
132 |
|
|
|
133 |
}#if end
|
|
|
134 |
|
|
|
135 |
#debug
|
|
|
136 |
#var_dump(__LINE__,$callShell);exit;
|
|
|
137 |
|
|
|
138 |
#函式說明:
|
|
|
139 |
#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
|
|
|
140 |
#回傳的結果:
|
|
|
141 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
142 |
#$result["function"],當前執行的function名稱
|
|
|
143 |
#$result["error"],錯誤訊息陣列.
|
|
|
144 |
#$result["content"],處理好的字串.
|
|
|
145 |
#$result["argu"],使用的參數.
|
|
|
146 |
#必填參數:
|
|
|
147 |
#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
|
|
|
148 |
$conf["inputArray"]=$callShell["escape"]["array"];
|
|
|
149 |
#可省略參數:
|
|
|
150 |
#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
|
|
|
151 |
$conf["spiltSymbol"]=" ";
|
|
|
152 |
#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
|
|
|
153 |
#$conf["skipEnd"]="";
|
|
|
154 |
#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
|
|
|
155 |
#$conf["spiltSymbolAtStart"]="";
|
|
|
156 |
#參考資料:
|
|
|
157 |
#無.
|
|
|
158 |
#備註:
|
|
|
159 |
#無.
|
|
|
160 |
$arrayToString=arrays::arrayToString($conf);
|
|
|
161 |
unset($conf);
|
|
|
162 |
|
|
|
163 |
#如果執行失敗
|
|
|
164 |
if($arrayToString["status"]==="false"){
|
|
|
165 |
|
|
|
166 |
#debug
|
|
|
167 |
var_dump($arrayToString);
|
|
|
168 |
|
|
|
169 |
#結束執行,回傳1給shell.
|
|
|
170 |
exit(1);
|
|
|
171 |
|
|
|
172 |
}#if end
|
|
|
173 |
|
|
|
174 |
#函式說明:
|
|
|
175 |
#透過proc來多執行序運作.
|
|
|
176 |
#回傳結果:
|
|
|
177 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
178 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
179 |
#$result["function"],當前執行的函式名稱.
|
|
|
180 |
#$result["argu"],使用的參數.
|
|
|
181 |
#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
182 |
#必填參數:
|
|
|
183 |
#$conf["cmds"],字串陣列,每個元素代表要執行的指令與參數.
|
|
|
184 |
$conf["cmds"]=array($arrayToString["content"]);
|
|
|
185 |
#可省略參數:
|
|
|
186 |
#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
|
|
|
187 |
$conf["wait"]="false";
|
|
|
188 |
#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
|
|
|
189 |
#$conf["workingDir"]=array("path");
|
|
|
190 |
#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
|
|
|
191 |
#$conf["envs"]=array(array("key"=>"value"));
|
|
|
192 |
#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
|
|
|
193 |
#$conf["executeBy"]=array("bash");
|
|
|
194 |
#參考資料:
|
|
|
195 |
#https://www.php.net/manual/en/function.proc-open.php
|
|
|
196 |
#https://www.php.net/manual/en/function.proc-get-status.php
|
|
|
197 |
#備註:
|
|
|
198 |
#無.
|
|
|
199 |
$proc=threads::proc($conf);
|
|
|
200 |
unset($conf);
|
|
|
201 |
|
|
|
202 |
#如果執行失敗
|
|
|
203 |
if($proc["status"]==="false"){
|
|
|
204 |
|
|
|
205 |
#debug
|
|
|
206 |
var_dump($proc);
|
|
|
207 |
|
|
|
208 |
#結束執行,回傳1給shell.
|
|
|
209 |
exit(1);
|
|
|
210 |
|
|
|
211 |
}#if end
|
|
|
212 |
|
|
|
213 |
#debug
|
|
|
214 |
#var_dump(__LINE__,$proc);exit;
|
|
|
215 |
|
|
|
216 |
#停1秒
|
|
|
217 |
sleep(1);
|
|
|
218 |
|
|
|
219 |
#提供config查詢的服務網址
|
|
|
220 |
$confServer="https://latest.qbpwcf.org/sample/config::server.php";
|
|
|
221 |
|
|
|
222 |
#初始化儲存 查詢的結果 陣列
|
|
|
223 |
$configGot=array();
|
|
|
224 |
|
|
|
225 |
#函式說明:
|
|
|
226 |
#查尋有使用 server 函式提供組態設定檔的服務,取得key的value.
|
|
|
227 |
#回傳結果:
|
|
|
228 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
229 |
#$result["error"],錯誤訊息陣列.
|
|
|
230 |
#$result["function"],當前執行的函數名稱.
|
|
|
231 |
#$result["rawContent"],得到的原始訊息.
|
|
|
232 |
#$result["content"],用json_decode後的結果;若"inBg"為"true",則其每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
233 |
#必填參數:
|
|
|
234 |
#$conf["server"],字串,組態服務設定服務的網址
|
|
|
235 |
$conf["server"]=$confServer;
|
|
|
236 |
#$conf["postName"],字串,POST變數的名稱,亦即要查尋的定義名稱.
|
|
|
237 |
$conf["postName"]="169.254.1.1";
|
|
|
238 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
239 |
$conf["fileArgu"]=__FILE__;
|
|
|
240 |
#可省略參數:
|
|
|
241 |
#$conf["cache"],字串,預設為"true",代表會啟用cache服務;反之為"false".
|
|
|
242 |
#$conf["cache"]="false";
|
|
|
243 |
#$conf["clientCacheDaemonSock"],字串,提供cache服務的 unix domain socket 檔案位置,預設為套件根目錄底下的"var/config::client/clientCacheDaemon.sock";.
|
|
|
244 |
#$conf["clientCacheDaemonSock"]="";
|
|
|
245 |
#$conf["inBg"],字串,預設為"false",代表在前景執行;反之為"true"代表在背景中執行,會強制將"cache"參數設為"false".
|
|
|
246 |
#$conf["inBg"]="true";
|
|
|
247 |
#參考資料:
|
|
|
248 |
#無.
|
|
|
249 |
#備註:
|
|
|
250 |
#目前僅能跟server函式提供的服務對接.
|
|
|
251 |
$configGot[]=config::client($conf);
|
|
|
252 |
unset($conf);
|
|
|
253 |
|
|
|
254 |
#函式說明:
|
|
|
255 |
#查尋有使用 server 函式提供組態設定檔的服務,取得key的value.
|
|
|
256 |
#回傳結果:
|
|
|
257 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
258 |
#$result["error"],錯誤訊息陣列.
|
|
|
259 |
#$result["function"],當前執行的函數名稱.
|
|
|
260 |
#$result["rawContent"],得到的原始訊息.
|
|
|
261 |
#$result["content"],用json_decode後的結果;若"inBg"為"true",則其每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
262 |
#必填參數:
|
|
|
263 |
#$conf["server"],字串,組態服務設定服務的網址
|
|
|
264 |
$conf["server"]=$confServer;
|
|
|
265 |
#$conf["postName"],字串,POST變數的名稱,亦即要查尋的定義名稱.
|
|
|
266 |
$conf["postName"]="configName1";
|
|
|
267 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
268 |
$conf["fileArgu"]=__FILE__;
|
|
|
269 |
#可省略參數:
|
|
|
270 |
#$conf["cache"],字串,預設為"true",代表會啟用cache服務;反之為"false".
|
|
|
271 |
#$conf["cache"]="false";
|
|
|
272 |
#$conf["clientCacheDaemonSock"],字串,提供cache服務的 unix domain socket 檔案位置,預設為套件根目錄底下的"var/config::client/clientCacheDaemon.sock";.
|
|
|
273 |
#$conf["clientCacheDaemonSock"]="";
|
|
|
274 |
#$conf["inBg"],字串,預設為"false",代表在前景執行;反之為"true"代表在背景中執行,會強制將"cache"參數設為"false".
|
|
|
275 |
#$conf["inBg"]="true";
|
|
|
276 |
#參考資料:
|
|
|
277 |
#無.
|
|
|
278 |
#備註:
|
|
|
279 |
#目前僅能跟server函式提供的服務對接.
|
|
|
280 |
$configGot[]=config::client($conf);
|
|
|
281 |
unset($conf);
|
|
|
282 |
|
|
|
283 |
#函式說明:
|
|
|
284 |
#查尋有使用 server 函式提供組態設定檔的服務,取得key的value.
|
|
|
285 |
#回傳結果:
|
|
|
286 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
287 |
#$result["error"],錯誤訊息陣列.
|
|
|
288 |
#$result["function"],當前執行的函數名稱.
|
|
|
289 |
#$result["rawContent"],得到的原始訊息.
|
|
|
290 |
#$result["content"],用json_decode後的結果;若"inBg"為"true",則其每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
291 |
#必填參數:
|
|
|
292 |
#$conf["server"],字串,組態服務設定服務的網址
|
|
|
293 |
$conf["server"]=$confServer;
|
|
|
294 |
#$conf["postName"],字串,POST變數的名稱,亦即要查尋的定義名稱.
|
|
|
295 |
$conf["postName"]="configName2";
|
|
|
296 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
297 |
$conf["fileArgu"]=__FILE__;
|
|
|
298 |
#可省略參數:
|
|
|
299 |
#$conf["cache"],字串,預設為"true",代表會啟用cache服務;反之為"false".
|
|
|
300 |
#$conf["cache"]="false";
|
|
|
301 |
#$conf["clientCacheDaemonSock"],字串,提供cache服務的 unix domain socket 檔案位置,預設為套件根目錄底下的"var/config::client/clientCacheDaemon.sock";.
|
|
|
302 |
#$conf["clientCacheDaemonSock"]="";
|
|
|
303 |
#$conf["inBg"],字串,預設為"false",代表在前景執行;反之為"true"代表在背景中執行,會強制將"cache"參數設為"false".
|
|
|
304 |
#$conf["inBg"]="true";
|
|
|
305 |
#參考資料:
|
|
|
306 |
#無.
|
|
|
307 |
#備註:
|
|
|
308 |
#目前僅能跟server函式提供的服務對接.
|
|
|
309 |
$configGot[]=config::client($conf);
|
|
|
310 |
unset($conf);
|
|
|
311 |
|
|
|
312 |
#如果程式最後狀態為進行中
|
|
|
313 |
if($proc["content"][0]["proc_get_status"]["running"]===true){
|
|
|
314 |
|
|
|
315 |
#debug
|
|
|
316 |
#var_dump(__LINE__,$proc["content"][0]);
|
|
|
317 |
|
|
|
318 |
#取得新狀態
|
|
|
319 |
$proc["content"][0]["proc_get_status"]=proc_get_status($proc["content"][0]["process"]);
|
|
|
320 |
|
|
|
321 |
#debug
|
|
|
322 |
#var_dump(__LINE__,$proc["content"][0]);
|
|
|
323 |
|
|
|
324 |
}#if end
|
| 226 |
liveuser |
325 |
|
| 11 |
liveuser |
326 |
#debug
|
|
|
327 |
#var_dump(__LINE__,$proc["content"][0]);
|
|
|
328 |
|
|
|
329 |
#如果有 $proc["content"][0]["content"]
|
|
|
330 |
if(isset($proc["content"][0]["content"])){
|
|
|
331 |
|
|
|
332 |
#取得clientCacheDaemon的標準輸出
|
|
|
333 |
$clientCacheDaemonStdOutput=$proc["content"][0]["content"];
|
|
|
334 |
|
|
|
335 |
#debug
|
|
|
336 |
#var_dump(__LINE__,gettype($proc["content"][0]["content"]));
|
|
|
337 |
|
|
|
338 |
#如果輸出為 resource
|
|
|
339 |
if(gettype($proc["content"][0]["content"])==="resource"){
|
|
|
340 |
|
|
|
341 |
#取得clientCacheDaemon的標準輸出
|
|
|
342 |
$clientCacheDaemonStdOutput=stream_get_contents($proc["content"][0]["content"]);
|
|
|
343 |
|
|
|
344 |
#關閉 output
|
|
|
345 |
fclose($proc["content"][0]["content"]);
|
|
|
346 |
|
|
|
347 |
}#if end
|
|
|
348 |
|
|
|
349 |
}#if end
|
|
|
350 |
|
|
|
351 |
#如果有 $proc["content"][0]["error"]
|
|
|
352 |
if(isset($proc["content"][0]["error"])){
|
|
|
353 |
|
|
|
354 |
#取得clientCacheDaemon的錯誤輸出
|
|
|
355 |
$clientCacheDaemonErrorOutput=$proc["content"][0]["error"];
|
|
|
356 |
|
|
|
357 |
#debug
|
|
|
358 |
#var_dump(__LINE__,gettype($proc["content"][0]["error"]));
|
|
|
359 |
|
|
|
360 |
#如果錯誤輸出為 resource
|
|
|
361 |
if(gettype($proc["content"][0]["error"])==="resource"){
|
|
|
362 |
|
|
|
363 |
#取得clientCacheDaemon的錯誤輸出
|
|
|
364 |
$clientCacheDaemonErrorOutput=stream_get_contents($proc["content"][0]["error"]);
|
|
|
365 |
|
|
|
366 |
#關閉 error
|
|
|
367 |
fclose($proc["content"][0]["error"]);
|
|
|
368 |
|
|
|
369 |
}#if end
|
|
|
370 |
|
|
|
371 |
}#if end
|
|
|
372 |
|
|
|
373 |
#debug
|
|
|
374 |
#var_dump(__LINE__,$proc["content"][0]["process"]);
|
|
|
375 |
|
|
|
376 |
#如果有 $proc["process"]
|
|
|
377 |
if(isset($proc["content"][0]["process"])){
|
|
|
378 |
|
| 226 |
liveuser |
379 |
#結束 clientCacheDaemon.php
|
| 11 |
liveuser |
380 |
$clientCacheDaemonStatusCode = proc_close($proc["content"][0]["process"]);
|
|
|
381 |
|
|
|
382 |
#debug
|
|
|
383 |
#var_dump(__LINE__,$clientCacheDaemonStatusCode);exit;
|
|
|
384 |
|
|
|
385 |
#如果 clientCacheDaemon.php 不是正常結束
|
|
|
386 |
if($clientCacheDaemonStatusCode!==0){
|
|
|
387 |
|
|
|
388 |
#提示 clientCacheDaemon.php 未正常結束
|
|
|
389 |
echo "clientCacheDaemon.php 未正常結束(".$clientCacheDaemonStatusCode.")".PHP_EOL;
|
|
|
390 |
|
|
|
391 |
#如果有 $clientCacheDaemonStdOutput
|
|
|
392 |
if(isset($clientCacheDaemonStdOutput)){
|
| 226 |
liveuser |
393 |
|
| 11 |
liveuser |
394 |
#提示 clientCacheDaemon.php 的標準輸出內容
|
|
|
395 |
echo "clientCacheDaemon.php 的標準輸出內容:".PHP_EOL.$clientCacheDaemonStdOutput.PHP_EOL;
|
| 226 |
liveuser |
396 |
|
| 11 |
liveuser |
397 |
}#if end
|
|
|
398 |
|
|
|
399 |
#如果有 $clientCacheDaemonErrorOutput
|
|
|
400 |
if(isset($clientCacheDaemonErrorOutput)){
|
| 226 |
liveuser |
401 |
|
| 11 |
liveuser |
402 |
#提示 clientCacheDaemon.php 的錯誤輸出內容
|
|
|
403 |
echo "clientCacheDaemon.php 的錯誤輸出內容:".PHP_EOL.$clientCacheDaemonErrorOutput.PHP_EOL;
|
| 226 |
liveuser |
404 |
|
| 11 |
liveuser |
405 |
}#if end
|
|
|
406 |
|
|
|
407 |
#debug
|
|
|
408 |
var_dump(__LINE__,$clientCacheDaemonStatusCode);
|
|
|
409 |
|
|
|
410 |
#結束執行,回傳1給shell.
|
|
|
411 |
exit(1);
|
|
|
412 |
|
|
|
413 |
}#if end
|
|
|
414 |
|
|
|
415 |
}#if end
|
|
|
416 |
|
|
|
417 |
#針對每個設定的查詢結果
|
|
|
418 |
foreach($configGot as $client){
|
|
|
419 |
|
|
|
420 |
#如果執行失敗
|
|
|
421 |
if($client["status"]==="false"){
|
|
|
422 |
|
|
|
423 |
#debug
|
|
|
424 |
var_dump(__LINE__,$client);
|
|
|
425 |
|
|
|
426 |
#結束執行,回傳1給shell.
|
|
|
427 |
exit(1);
|
|
|
428 |
|
|
|
429 |
}#if end
|
|
|
430 |
|
|
|
431 |
}#foreach end
|
| 226 |
liveuser |
432 |
|
| 11 |
liveuser |
433 |
#印出結果
|
|
|
434 |
var_dump($configGot);
|
|
|
435 |
|
| 226 |
liveuser |
436 |
?>
|