| 6 |
liveuser |
1 |
#!/usr/bin/php
|
|
|
2 |
<?php
|
|
|
3 |
|
|
|
4 |
/*
|
|
|
5 |
|
|
|
6 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 239 |
liveuser |
7 |
Copyright (C) 2014~2026 MIN ZHI, CHEN
|
| 6 |
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
|
| 97 |
liveuser |
33 |
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../../../usr/bin/libexec/folderOfUsrLib.php"),$output,$status);
|
| 6 |
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 首位
|
| 97 |
liveuser |
53 |
exec("cd ".pathinfo(__FILE__)["dirname"]."/../../../../usr/".$folderOfUsrLib."/qbpwcf;pwd;",$output,$status);
|
| 6 |
liveuser |
54 |
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
|
|
|
55 |
|
|
|
56 |
#匯入套件
|
|
|
57 |
require_once("allInOneForJson.php");
|
|
|
58 |
|
|
|
59 |
#建議的log位置
|
|
|
60 |
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";
|
|
|
61 |
|
|
|
62 |
#函式說明:
|
|
|
63 |
#執行程式時,依照需要增加記憶體的上限.
|
|
|
64 |
#回傳結果:
|
|
|
65 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
66 |
#$result["error"],錯誤訊息陣列.
|
|
|
67 |
#$result["function"],當前執行的函數名稱.
|
|
|
68 |
#$result["argu"],使用的參數.
|
|
|
69 |
#$result["content"],程式執行後的結果.
|
|
|
70 |
#必填參數:
|
|
|
71 |
#$conf["cmd"],字串參數,要執行的指令.
|
|
|
72 |
#$conf["cmd"]="uname";
|
|
|
73 |
#$conf["cmd"]="echo";
|
|
|
74 |
#$conf["cmd"]="ps";
|
|
|
75 |
$conf["cmd"]="sleep";
|
|
|
76 |
#可省略參數:
|
|
|
77 |
#$conf["params"],陣列字串參數,每個元素代表依序哦昂使用的參數.
|
|
|
78 |
#$conf["params"]=array("-a");
|
|
|
79 |
#$conf["params"]=array("Hello World");
|
|
|
80 |
#$conf["params"]=array("auxwf");
|
|
|
81 |
$conf["params"]=array("5",";","ps","auxwf","|","cat");
|
|
|
82 |
#參考資料:
|
|
|
83 |
#https://www.php.net/manual/en/function.memory-get-usage.php
|
|
|
84 |
#https://www.php.net/manual/en/ini.core.php#ini.memory-limit
|
|
|
85 |
#備註:
|
|
|
86 |
#無.
|
|
|
87 |
$runWithAutoAddMemoryDaemon=sock::runWithAutoAddMemoryDaemon($conf);
|
|
|
88 |
unset($conf);
|
|
|
89 |
|
|
|
90 |
#如果執行失敗
|
|
|
91 |
if($runWithAutoAddMemoryDaemon["status"]==="false"){
|
|
|
92 |
|
|
|
93 |
#函式說明:
|
|
|
94 |
#撰寫log
|
|
|
95 |
#回傳結果:
|
|
|
96 |
#$result["status"],狀態,"true"或"false".
|
|
|
97 |
#$result["error"],錯誤訊息陣列.
|
|
|
98 |
#$result["function"],當前函式的名稱.
|
|
|
99 |
#$result["argu"],使用的參數.
|
|
|
100 |
#必填參數:
|
|
|
101 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
102 |
$conf["path"]=$logFile;
|
|
|
103 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
104 |
$conf["content"]=$runWithAutoAddMemoryDaemon;
|
|
|
105 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
106 |
$conf["fileArgu"]=__FILE__;
|
|
|
107 |
#可省略參數:
|
|
|
108 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
109 |
#$conf["rewrite"]="false";
|
|
|
110 |
#參考資料:
|
|
|
111 |
#無.
|
|
|
112 |
#備註:
|
|
|
113 |
#無.
|
|
|
114 |
$record=logs::record($conf);
|
|
|
115 |
unset($conf);
|
| 224 |
liveuser |
116 |
|
| 6 |
liveuser |
117 |
#結束執行
|
|
|
118 |
exit;
|
|
|
119 |
|
|
|
120 |
}#if end
|
|
|
121 |
|
|
|
122 |
#印出結果
|
|
|
123 |
var_dump($runWithAutoAddMemoryDaemon);
|
|
|
124 |
|
|
|
125 |
?>
|