Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14 liveuser 1
<?php
2
 
3
#使用命名空間
4
namespace qbpwcf;
5
 
6
#匯入外部套件
7
include("../allInOne.php");
8
 
9
#提示目前執行的方法
10
echo "<hr>external::callShell - testCase 1<p>";
11
 
12
/*
13
 
14
#涵式說明:
15
#呼叫shell執行系統命令,並取得回傳的內容.
16
#回傳的結果:
17
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
18
#$result["error"],錯誤訊息陣列.
19
#$result["function"],當前執行的函數名稱.
20
#$result["cmd"],執行的指令內容.
21
#$result["output"],爲執行完二元碼後的輸出陣列.
22
#$result["outputFromFile"]["fileContent"],取得輸出的內容陣列.
23
#$result["outputFromFile"]["lineCount"],取得輸出內容總共的行數.
24
#$result["outputFromFile"]["fullContent"],取得輸出的內容陣列.
25
#必填的參數
26
#$conf["command"],字串.
27
$conf["command"]="uname -a";#要執行的指令與參數.
28
#可省略參數:
29
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
30
#$conf["enablePrintDescription"]="true";
31
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
32
#$conf["printDescription"]="";
33
#參考資料:
34
#exec=>http://php.net/manual/en/function.exec.php
35
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
36
var_dump(external::callShell($conf));
37
unset($conf);
38
 
39
*/
40
 
41
#提示目前執行的方法
42
echo "<hr>external::callShell - testCase 2<p>";
43
 
44
/*
45
 
46
#涵式說明:
47
#呼叫shell執行系統命令,並取得回傳的內容.
48
#回傳的結果:
49
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
50
#$result["error"],錯誤訊息陣列.
51
#$result["function"],當前執行的函數名稱.
52
#$result["cmd"],執行的指令內容.
53
#$result["output"],爲執行完二元碼後的輸出陣列.
54
#必填的參數
55
#$conf["command"],字串,要執行的指令與.
56
$conf["command"]="dnf check-update";
57
#可省略參數:
58
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
59
#$conf["argu"]=array("");
60
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
61
#$conf["enablePrintDescription"]="true";
62
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
63
#$conf["printDescription"]="";
64
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
65
#$conf["escapeshellarg"]="false";
66
#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
67
$conf["username"]="root";
68
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
69
$conf["password"]="superFedoraLinux";
70
#備註:
71
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
72
#參考資料:
73
#exec=>http://php.net/manual/en/function.exec.php
74
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
75
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
76
var_dump(external::callShell($conf));
77
unset($conf);
78
 
79
*/
80
 
81
#提示目前執行的方法
82
echo "<hr>external::callShell - testCase 3<p>";
83
 
84
/* 因為apache無法執行java所以會失敗
85
 
86
#涵式說明:
87
#呼叫shell執行系統命令,並取得回傳的內容.
88
#回傳的結果:
89
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
90
#$result["error"],錯誤訊息陣列.
91
#$result["function"],當前執行的函數名稱.
92
#$result["cmd"],執行的指令內容.
93
#$result["output"],爲執行完二元碼後的輸出陣列.
94
#$result["outputFromFile"]["fileContent"],取得輸出的內容陣列.
95
#$result["outputFromFile"]["lineCount"],取得輸出內容總共的行數.
96
#$result["outputFromFile"]["fullContent"],取得輸出的內容陣列.
97
#必填的參數
98
#$conf["command"],字串.
99
$conf["command"]="java";#要執行的指令與參數.
100
#可省略參數:
101
#$conf["argu"],字串,指令搭配的參數,預設為"".
102
$conf["argu"][]="externel/webService";
103
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
104
#$conf["enablePrintDescription"]="true";
105
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
106
#$conf["printDescription"]="";
107
#參考資料:
108
#exec=>http://php.net/manual/en/function.exec.php
109
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
110
var_dump(external::callShell($conf));
111
unset($conf);
112
 
113
*/
114
 
115
#提示目前執行的方法
116
echo "<hr>external::callShell - testCase 4<p>";
117
 
118
/* 
119
 
120
#涵式說明:
121
#呼叫shell執行系統命令,並取得回傳的內容.
122
#回傳的結果:
123
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
124
#$result["error"],錯誤訊息陣列.
125
#$result["function"],當前執行的函數名稱.
126
#$result["cmd"],執行的指令內容.
127
#$result["output"],爲執行完二元碼後的輸出陣列.
128
#必填的參數
129
#$conf["command"],字串,要執行的指令與.
130
$conf["command"]="lshw";
131
#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
132
$conf["fileArgu"]=__FILE__; 
133
#可省略參數:
134
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
135
#$conf["argu"]=array("");
136
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
137
#$conf["enablePrintDescription"]="true";
138
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
139
#$conf["printDescription"]="";
140
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
141
#$conf["escapeshellarg"]="false";
142
#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
143
#$conf["username"]="root";
144
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
145
#$conf["password"]="superFedoraLinux";
146
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
147
#$conf["useScript"]="";
148
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
149
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
150
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要.
151
$conf["inBackGround"]="true";
152
#備註:
153
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
154
#參考資料:
155
#exec=>http://php.net/manual/en/function.exec.php
156
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
157
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
158
var_dump(external::callShell($conf));
159
unset($conf);
160
 
161
*/
162
 
163
#提示目前執行的方法
164
echo "<hr>external::callShell - testCase 5<p>";
165
 
166
/*
167
 
168
#涵式說明:
169
#呼叫shell執行系統命令,並取得回傳的內容.
170
#回傳的結果:
171
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
172
#$result["error"],錯誤訊息陣列.
173
#$result["function"],當前執行的函數名稱.
174
#$result["cmd"],執行的指令內容.
175
#$result["output"],爲執行完二元碼後的輸出陣列.
176
#必填的參數
177
#$conf["command"],字串,要執行的指令與.
178
$conf["command"]="uname -a";
179
#$conf["fileArgu"],字串,變數__FILE__的內容.
180
$conf["fileArgu"]=__FILE__;		
181
#可省略參數:
182
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
183
#$conf["argu"]=array("");
184
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
185
#$conf["arguIsAddr"]=array();
186
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
187
#$conf["enablePrintDescription"]="true";
188
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
189
#$conf["printDescription"]="";
190
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
191
#$conf["escapeshellarg"]="false";
192
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
193
#$conf["username"]="";
194
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
195
#$conf["password"]="";
196
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
197
$conf["useScript"]="true";
198
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
199
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
200
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
201
#$conf["inBackGround"]="";
202
#備註:
203
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
204
#參考資料:
205
#exec=>http://php.net/manual/en/function.exec.php
206
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
207
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php			
208
$callShell=external::callShell($conf);
209
unset($conf);
210
var_dump($callShell);
211
 
212
*/
213
 
214
#提示目前執行的方法
215
echo "<hr>external::callShell - testCase 6<p>";
216
 
217
/*
218
 
219
#涵式說明:
220
#呼叫shell執行系統命令,並取得回傳的內容.
221
#回傳的結果:
222
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
223
#$result["error"],錯誤訊息陣列.
224
#$result["function"],當前執行的函數名稱.
225
#$result["cmd"],執行的指令內容.
226
#$result["output"],爲執行完二元碼後的輸出陣列.
227
#必填的參數
228
#$conf["command"],字串,要執行的指令與.
229
$conf["command"]="ls";
230
#$conf["fileArgu"],字串,變數__FILE__的內容.
231
$conf["fileArgu"]=__FILE__;	
232
#可省略參數:
233
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
234
$conf["argu"]=array("-alh","/home/liveuser/Downloads");
235
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
236
$conf["arguIsAddr"]=array("false","true");
237
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
238
#$conf["enablePrintDescription"]="true";
239
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
240
#$conf["printDescription"]="";
241
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
242
#$conf["escapeshellarg"]="false";
243
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
244
#$conf["username"]="";
245
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
246
#$conf["password"]="";
247
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
248
#$conf["useScript"]="true";
249
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
250
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
251
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
252
#$conf["inBackGround"]="";
253
#備註:
254
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
255
#參考資料:
256
#exec=>http://php.net/manual/en/function.exec.php
257
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
258
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php			
259
$callShell=external::callShell($conf);
260
unset($conf);
261
var_dump($callShell);
262
 
263
*/
264
 
265
#提示目前執行的方法
266
echo "<hr>external::callJava<p>";
267
 
268
/*
269
 
270
#編譯java檔
271
#涵式說明:
272
#呼叫shell執行系統命令,並取得回傳的內容.
273
#回傳的結果:
274
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
275
#$result["error"],錯誤訊息陣列
276
#$result["output"],爲執行完二元碼後的輸出陣列
277
#$result["function"],當前執行的函數名稱
278
#必填的參數
279
#$conf["command"],字串.
280
$conf["command"]="javac";#要執行的指令與參數.
281
#可省略參數:
282
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
283
$conf["argu"]=array("externalT/webService.java");
284
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
285
#$conf["enablePrintDescription"]="true";
286
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
287
#$conf["printDescription"]="";
288
#參考資料:
289
#http://php.net/manual/en/function.exec.php
290
var_dump(external::callShell($conf));
291
unset($conf);
292
 
293
#涵式說明:
294
#測試php呼叫java後回傳的結果 
295
#回傳的結果:
296
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
297
#$result["error"],錯誤訊息陣列
298
#$result["output"],爲執行完二元碼後的輸出陣列
299
#必填的參數:
300
$conf["javaClassFileAddress"]="externalT/webService";#java class檔案的位置與名稱,附檔名(.class)不用附上。
301
#可省略的參數:
302
$conf["arguments"]="-t1";#要給java class檔案的參數
303
#參考資料:
304
#http://php.net/manual/en/function.exec.php
305
var_dump(external::callJava($conf));
306
unset($conf);
307
 
308
*/
309
 
310
#提示目前執行的方法
311
echo "<hr>external::execByteCode<p>";
312
 
313
/*
314
 
315
#涵式說明:
316
#測試php呼叫shell後回傳的結果
317
#回傳的結果:
318
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
319
#$result["error"],錯誤訊息陣列
320
#$result["output"],爲執行完二元碼後的輸出陣列
321
#必填的參數
322
$conf["exeFileAddress"]="externalT/cmd.bin";#可執行檔的位置與名稱
323
#可省略的參數:
324
$conf["arguments"]="ls -al";#要給執行檔的參數
325
#參考資料:
326
#http://php.net/manual/en/function.exec.php
327
var_dump(external::execByteCode($conf));
328
unset($conf);
329
 
330
*/
331
 
332
#提示目前執行的方法
333
echo "<hr>external::compileCppThenDownload<p>";
334
 
335
/*
336
 
337
#函式說明:
338
#編譯C++檔案,下載輸出的2元碼.
339
#回傳的結果:
340
#當 $conf["noDownload"] 設為 "true" 或執行出錯時 才會有回傳的結果.
341
#$result["status"],"true"代表執行正常,"false"代表執行失敗.
342
#$result["error"],錯誤訊息陣列.
343
#$result["function"],正在執行的函式
344
#$result["content"],編譯好的檔案位置.
345
#必填的參數:
346
#$conf["cppAddress"],字串,要編譯的cpp檔位置,請加上cpp副檔名.
347
$conf["cppAddress"]="externalT/compileCppThenDownload.cpp";
348
#可省略的參數:
349
#$conf["outputAddress"],字串,輸出的檔案位置與名稱,請加上附檔名,預設為".bin/cppOriFileName.bin".
350
#$conf["outputAddress"]="";
351
#$conf["noDownload"],字串,"true"為不要下載,改成回傳編譯好的檔案位置.
352
$conf["noDownload"]="true";
353
#備註:
354
#測試中...
355
var_dump(external::compileCppThenDownload($conf));
356
unset($conf);
357
 
358
*/
359
 
360
#提示目前執行的方法
361
echo "<hr>external::callShellMulti - testCase 1<p>";
362
 
363
/*
364
 
365
#涵式說明:
366
#呼叫shell執行系統命令,並取得回傳的內容.
367
#回傳的結果:
368
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
369
#$result["error"],錯誤訊息陣列.
370
#$result["function"],當前執行的函數名稱.
371
#$result["cmd"],執行的指令內容.
372
#$result["output"],爲執行完二元碼後的輸出陣列.
373
#必填的參數
374
#$conf["command"],字串陣列,要執行的指令與.
375
$conf["command"]=array("uname -a","ls","pwd","date");
376
#可省略參數:
377
#$conf["argu"],陣字串列,執行各個$conf["command"]時指令搭配的參數,預設為空陣列.
378
#$conf["argu"]=array(array(""));
379
#$conf["enablePrintDescription"],字串陣列,執行各個$conf["command"]時是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
380
#$conf["enablePrintDescription"]=array("false");
381
#$conf["printDescription"],字串陣列,執行各個$conf["command"]前要印出來的的文字,預設為$conf["command"]的內容,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
382
#$conf["printDescription"]=array("");
383
#$conf["escapeshellarg"],字串陣列,執行各個$conf["command"]時是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false",其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
384
#$conf["escapeshellarg"]=array("false");
385
#備註:
386
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
387
#參考資料:
388
#exec=>http://php.net/manual/en/function.exec.php
389
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
390
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
391
var_dump(external::callShellMulti($conf));
392
unset($conf);
393
 
394
*/
395
 
396
#提示目前執行的方法
397
echo "<hr>external::multiThreadsShell - testCase 1<p>";
398
 
399
/*
400
 
401
#涵式說明:
402
#運用nohup與&來達到雖依序執行但不等待前一個指令執行完再執行下一個指令,形成假多工的執行每個指令.
403
#回傳結果: 
404
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
405
#$result["error"],錯誤訊息陣列.
406
#$result["function"],當前執行的函數名稱.
407
#$result["cmd"],執行的指令內容.
408
#$result["output"],爲執行完二元碼後的輸出陣列.
409
#必填參數:
410
#$conf["command"],字串陣列,要執行的指令與.
411
$conf["command"]=array("php -r 'sleep(100);'","php -r 'sleep(100);'","php -r 'sleep(100);'","php -r 'sleep(100);'");
412
#$conf["fileArgu"],字串,變數__FILE__的內容.
413
$conf["fileArgu"]=__FILE__;		
414
#可省略參數:
415
#$conf["argu"],二維陣列字串,每個指令搭配的參數,預設為空陣列.
416
#$conf["argu"]=array(array());
417
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
418
#$conf["enablePrintDescription"]="true";
419
#$conf["printDescription"],字串陣列,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
420
#$conf["printDescription"]=array("");
421
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
422
$conf["escapeshellarg"]="false";
423
#$conf["username"],字串陣列,每個指令要用什麼使用者來執行,預設為執行php使用者,該參數不適用於apache環境.
424
#$conf["username"]=array("");
425
#$conf["password"],字串陣列,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
426
#$conf["password"]=array("");
427
var_dump(external::multiThreadsShell($conf));
428
unset($conf);
429
 
430
*/
431
 
432
#提示目前執行的方法
433
echo "<hr>external::callShellInBg - testCase 1<p>";
434
 
435
/*
436
 
437
#涵式說明:
438
#呼叫shell執行系統命令,並取得回傳的內容與pid.
439
#回傳的結果:
440
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
441
#$result["error"],錯誤訊息陣列.
442
#$result["function"],當前執行的函數名稱.
443
#$result["cmd"],執行的指令內容.
444
#$result["output"],爲執行完二元碼後的輸出陣列.
445
#必填的參數
446
#$conf["command"],字串,要執行的指令.
447
$conf["command"]="ls";
448
#$conf["fileArgu"],字串,變數__FILE__的內容.
449
$conf["fileArgu"]=__FILE__;		
450
#備註:
451
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,透過su使用root身份可能會被selinux阻擋.
452
#參考資料:
453
#http://php.net/manual/en/function.exec.php	
454
$callShellV2=external::callShellInBg($conf);
455
unset($conf);
456
 
457
#如果執行錯誤
458
if($callShellV2["status"]==="status"){
459
 
460
	#印出內容
461
	var_dump($callShellV2);
462
 
463
	#結束程式
464
	exit;
465
 
466
	}#if end
467
 
468
#反之
469
else{
470
 
471
	#印出內容
472
	var_dump($callShellV2);
473
 
474
	}#else end
475
 
476
*/	
477
 
478
#提示目前執行的方法
479
echo "<hr>external::callShellInBg - testCase 2<p>";
480
 
481
/*
482
 
483
#涵式說明:
484
#呼叫shell執行系統命令,並取得回傳的內容與pid.
485
#回傳的結果:
486
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
487
#$result["error"],錯誤訊息陣列.
488
#$result["function"],當前執行的函數名稱.
489
#$result["cmd"],執行的指令內容.
490
#$result["output"],爲執行完二元碼後的輸出陣列.
491
#必填的參數
492
#$conf["command"],字串,要執行的指令.
493
$conf["command"]="ping 127.0.0.1";
494
#$conf["fileArgu"],字串,變數__FILE__的內容.
495
$conf["fileArgu"]=__FILE__;		
496
#備註:
497
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,透過su使用root身份可能會被selinux阻擋.
498
#參考資料:
499
#http://php.net/manual/en/function.exec.php	
500
$callShellV2=external::callShellInBg($conf);
501
unset($conf);
502
 
503
#如果執行錯誤
504
if($callShellV2["status"]==="status"){
505
 
506
	#印出內容
507
	var_dump($callShellV2);
508
 
509
	#結束程式
510
	exit;
511
 
512
	}#if end
513
 
514
#反之
515
else{
516
 
517
	#印出內容
518
	var_dump($callShellV2);
519
 
520
	}#else end
521
 
522
*/	
523
 
524
#提示目前執行的方法
525
echo "<hr>external::killProcess - testCase 1<p>";
526
 
527
/*
528
 
529
#涵式說明:
530
#呼叫shell執行系統命令,中止執行中的pid.
531
#回傳的結果:
532
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
533
#$result["error"],錯誤訊息陣列.
534
#$result["function"],當前執行的函數名稱.
535
#$result["warning"],警告訊息陣列.
536
#$result["cmd"],執行的指令內容.
537
#$result["output"],爲執行完二元碼後的輸出陣列.
538
#$result["runing"],程式是否還在執行.
539
#必填的參數
540
#$conf["fileArgu"],字串,變數__FILE__的內容.
541
$conf["fileArgu"]=__FILE__;	
542
#$conf["pid"],字串,執行序的pid.
543
$conf["pid"]=$callShellV2["pid"];
544
#$conf["cmd"],字串,要中止的指令關鍵字.
545
$conf["cmd"]="ping 127.0.0.1";	
546
#備註:
547
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,透過su使用root身份可能會被selinux阻擋.
548
#參考資料:
549
#http://php.net/manual/en/function.exec.php
550
$killProcess=external::killProcess($conf);
551
unset($conf);
552
 
553
#如果執行錯誤
554
if($killProcess["status"]==="status"){
555
 
556
	#印出內容
557
	var_dump($killProcess);
558
 
559
	#結束程式
560
	exit;
561
 
562
	}#if end
563
 
564
#反之
565
else{
566
 
567
	#印出內容
568
	var_dump($killProcess);
569
 
570
	}#else end
571
 
572
*/
573
 
574
#提示目前執行的方法
575
echo "<hr>external::callShellExecInBg - testCase 1<p>";
576
 
577
/*
578
 
579
#涵式說明:
580
#呼叫shell_exec執行系統命令,並取得回傳儲存輸出內容的檔案與pid.
581
#回傳的結果:
582
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
583
#$result["error"],錯誤訊息陣列.
584
#$result["function"],當前執行的函數名稱.
585
#$result["cmd"],執行的指令內容.
586
#$result["fullCmd"],執行的完整指令
587
#$result["content"],爲執行完二元碼後的輸出陣列.
588
#$result["runing"],程式是否還在執行.
589
#$result["pid"],pid.
590
#必填的參數
591
#$conf["command"],字串,要執行的指令.
592
$conf["command"]="echo \"123\r\n456\r\n789\r\n\"";
593
#$conf["fileArgu"],字串,變數__FILE__的內容.
594
$conf["fileArgu"]=__FILE__;		
595
#備註:
596
#不是所有指令都能用apache的身份執行,目前已知java,javac,ping指令無法執行,透過su使用root身份可能會被selinux阻擋.
597
#參考資料:
598
#http://php.net/manual/en/function.exec.php	
599
$callShellExecInBg=external::callShellExecInBg($conf);
600
unset($conf);
601
 
602
#如果執行失敗
603
if($callShellExecInBg["status"]==="false"){
604
 
605
	#印出內容
606
	var_dump($callShellExecInBg);
607
 
608
	#結束程式
609
	exit;
610
 
611
	}#if end	
612
 
613
#反之
614
else{
615
 
616
	#印出內容
617
	var_dump($callShellExecInBg);
618
 
619
	}#else end
620
 
621
*/	
622
 
623
#提示目前執行的方法
624
echo "<hr>external::timeout - testCase 1<p>";
625
 
626
/*
627
 
628
#函式說明:
629
#檢查目標程式是否執行超過時間,將之中止. 
630
#回傳結果
631
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
632
#$result["error"],錯誤訊息陣列.
633
#$result["function"],當前執行的函數名稱.	
634
#$result["timeout"],程序是否timeout,"true"代表是,"false"代表不是.
635
#必填參數:
636
#$conf["pid"],字串,程序的id.
637
$conf["pid"]="3972";
638
#$conf["cmd"],字串,程序的指令.
639
$conf["cmd"]="php test.php";
640
#$conf["fileArgu"],字串,__FILE__的內容,__FILE__的內容.
641
$conf["fileArgu"]=__FILE__;
642
#$conf["timeout"],整數,多少時間過後要timeout,單位為秒.
643
$conf["timeout"]=60;
644
$timeout=external::timeout($conf);
645
unset($conf);	
646
 
647
#如果處理timeout失敗
648
if($timeout["status"]==="false"){
649
 
650
	#印出內容
651
	var_dump($timeout);
652
 
653
	#結束執行
654
	exit;
655
 
656
	}#if end	
657
 
658
#印出內容
659
var_dump($timeout);	
660
 
661
*/
662
 
663
?>