Rev 140 | Rev 162 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php/*QBPWCF, Quick Build PHP website Component base on Fedora Linux.Copyright (C) 2015~2024 Min-Jhin,ChenThis file is part of QBPWCF.QBPWCF is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.QBPWCF is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with QBPWCF. If not, see <http://www.gnu.org/licenses/>.*/namespace qbpwcf;/*類別說明:提供多執行序應用的類別.參考資料:https://www.php.net/manual/en/book.parallel.php備註:建構中*/class threads{/*#函式說明:#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$method,物件,為物件實體或類別名稱,會自動置入該參數.#$arguments,陣列,為呼叫方法時所用的參數.#可省略參數:#無.#參考資料:#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic#備註:#無.*/public function __call($method,$arguments){#取得當前執行的函式$result["function"]=__FUNCTION__;#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";#設置所丟入的參數$result["error"][]=$arguments;#回傳結果return $result;}#function __call end/*#函式說明:#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$method,物件,為物件實體或類別名稱,會自動置入該參數.#$arguments,陣列,為呼叫方法時所用的參數.#可省略參數:#無.#參考資料:#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic#備註:#無.*/public static function __callStatic($method,$arguments){#取得當前執行的函式$result["function"]=__FUNCTION__;#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";#設置所丟入的參數$result["error"][]=$arguments;#回傳結果return $result;}#function __callStatic end/*#函式說明:#展示多執行序運作.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#無.#可省略參數:#無.#參考資料:#無.#備註:#無.改用 proc 試試 https://www.php.net/manual/en/function.proc-open.php*/public static function demo(){#執行demovar_dump(self::proc_demo());}#function demo end/*#函式說明:#透過proc展示多執行序運作.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#無.#可省略參數:#無.#參考資料:#https://www.php.net/manual/en/function.proc-open.php#備註:#無.*/public static function proc_demo(){#初始化 descriptorspec$descriptorspec = array();#stdin is a pipe that the child will read from$descriptorspec[]=array("pipe", "r");#stdout is a pipe that the child will write to$descriptorspec[]=array("pipe", "w");#stderr is a pipe that the child will write to$descriptorspec[]=array("pipe", "w");#The initial working dir for the command. This must be an absolute directory path, or null if you want to use the default value (the working dir of the current PHP process)$cwd = null;#An array with the environment variables for the command that will be run, or null to use the same environment as the current PHP process$env = array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");#初始化儲存要多執行序執行的程式$codes=array();#初始化要demo用的url$demoUrl="https://qbpwc.sourceforge.io/";#要多執行序執行的程式1$codes[]=array("bash","curl -v -L --ssl-reqd ".$demoUrl);#要多執行序執行的程式2$codes[]=array("bash","curl -v -L --ssl-reqd ".$demoUrl);#要多執行序執行的程式3$codes[]=array("bash","curl -v -L --ssl-reqd ".$demoUrl);#debug#var_dump(__LINE__,$codes);#儲存每個要執行的程式資訊$process=array();#針對每個要執行的程式內容foreach($codes as $index=>$code){#取得要用什麼程式執行$executeBy=$code[0];#取得要執行的程式內容$code=$code[1];#運行 php 程式,並儲存 resource$process[$index]["resource"] = proc_open($executeBy, $descriptorspec, $pipes, $cwd, $env);#儲存對應的 pipes$process[$index]["pipes"]=$pipes;#debug#var_dump(__LINE__,$process[$index]);#如果有成功執行if(is_resource($process[$index]["resource"])){#$pipes now looks like this:#0 => writeable handle connected to child stdin#1 => readable handle connected to child stdout#2 => readable handle connected to child stdin#寫入內容作為 $executeBy 的輸入$bytes2write=fwrite($process[$index]["pipes"][0], $code);#debug#var_dump(__LINE__,$bytes2write);#結束輸入fclose($process[$index]["pipes"][0]);}#if end#反之,代表運行 php 失敗else{#初始化暫存執行結果的變數$cmdRes=array();#設置執行失敗$cmdRes["status"]="false";#設置執行錯誤訊息$cmdRes["error"]="execute program by \"".$executeBy."\" failed!";#設置執行結果$result["content"][]=$cmdRes;}#else end}#foreach end#debug#var_dump(__LINE__,$process);#針對每個回饋foreach($process as $index => $ps){#取得 proc resource$resource=$ps["resource"];#取得標準輸出$stdout=stream_get_contents($process[$index]["pipes"][1]);#取得錯誤輸出$stderr=stream_get_contents($process[$index]["pipes"][2]);#debug#var_dump($stdout);#初始化暫存執行狀況的變數$cmdRes=array();#設置執行失敗訊息$cmdRes["error"]=$stderr;#設置執行結果$cmdRes["content"]=$stdout;#debug#var_dump($cmdRes);#結束讀取標準輸出fclose($process[$index]["pipes"][1]);#結束讀取錯誤輸出fclose($process[$index]["pipes"][2]);#It is important that you close any pipes before calling proc_close in order to avoid a deadlock$cmdRes["statusCode"] = proc_close($resource);#debug#var_dump($cmdRes["statusCode"]);#預設執行不正常$cmdRes["status"]="false";#如果執行正常if($cmdRes["statusCode"]===0){#設置執行正常$cmdRes["status"]="true";}#if end#保存結果$result["content"][]=$cmdRes;#debug#var_dump($result);}#foreach end#設置執行正常$result["status"]="true";#debug#var_dump($result);#回傳結果return $result;}#function proc_demo end/*#函式說明:#透過proc來多執行序運作.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$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"代表程序的資訊.#必填參數:#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.#$conf["cmds"]=array();#可省略參數:#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.#$conf["wait"]="false";#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.#$conf["timeout"]=array("10");#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.#$conf["workingDir"]=array("path");#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");#$conf["envs"]=array(array("key"=>"value"));#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".#$conf["executeBy"]=array("bash");#參考資料:#https://www.php.net/manual/en/function.proc-open.php#https://www.php.net/manual/en/function.proc-get-status.php#https://www.php.net/manual/en/function.proc-terminate.php#備註:#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.*/public static function proc(&$conf){#初始化要回傳的變數$result=array();#初始化當前執行的函數名稱$result["function"]=__FUNCTION__;#如果 $conf 不為陣列if(gettype($conf)!=="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf===null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#取得使用的參數$result["argu"]=$conf;#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],執行不正常結束的錯訊息陣列.#$result["simpleError"],簡單表示的錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可省略參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cmds");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("wait","workingDir","envs","executeBy","timeout");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("wait","workingDir","envs","executeBy","timeout");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","array","array","array");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true",null,null,null,null);#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".#$conf["disallowAllSkipableVarNotExist"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("");#參考資料:#array_keys=>http://php.net/manual/en/function.array-keys.php#備註:#無.$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果 $checkArguments["status"] 等於 "false"if($checkArguments["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果 $checkArguments["passed"] 等於 "false"if($checkArguments["passed"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#初始化 descriptorspec$descriptorspec = array();#stdin is a pipe that the child will read from$descriptorspec[]=array("pipe", "r");#stdout is a pipe that the child will write to$descriptorspec[]=array("pipe", "w");#stderr is a pipe that the child will write to$descriptorspec[]=array("pipe", "w");#The initial working dir for the command. This must be an absolute directory path, or null if you want to use the default value (the working dir of the current PHP process)$defaultCWD = null;#初始化儲存每個指令的working dir.$cwds=array();#有幾個指令就執行幾次for($i=0;$i<count($conf["cmds"]);$i++){#設置預設working dir$cwds[]=$defaultCWD;}#for end#如果有設置 workingDirif(isset($conf["workingDir"])){#如果數量符合if(count($conf["cmds"])===count($conf["workingDir"])){#有幾個指令就執行幾次for($i=0;$i<count($conf["cmds"]);$i++){#預設為指定數值$cwds[]=$conf["workingDir"][$i];}#for end}#if end}#if end#An array with the environment variables for the command that will be run, or null to use the same environment as the current PHP process$defaultENV = array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");#初始化儲存每個指令的環境變數.$envs=array();#有幾個指令就執行幾次for($i=0;$i<count($conf["cmds"]);$i++){#設置預設環境變數$envs[]=$defaultENV;}#for end#如果有設置 envsif(isset($conf["envs"])){#如果數量符合if(count($conf["cmds"])===count($conf["envs"])){#有幾個指令就執行幾次for($i=0;$i<count($conf["cmds"]);$i++){#預設為指定數值$envs[]=$conf["envs"][$i];}#for end}#if end}#if end#預設程式都透過 bash 來執行$defaultExecBy="bash";#初始化儲存每個指令要透過什麼程式執行$executeBys=array();#有幾個指令就執行幾次for($i=0;$i<count($conf["cmds"]);$i++){#設置預設環境變數$executeBys[]=$defaultExecBy;}#for end#如果有設置 executeByif(isset($conf["executeBy"])){#如果數量符合if(count($conf["cmds"])===count($conf["executeBy"])){#初始化儲存每個指令要透過什麼程式執行$executeBys=array();#有幾個指令就執行幾次for($i=0;$i<count($conf["cmds"]);$i++){#預設為指定數值$executeBys[]=$conf["executeBy"][$i];}#for end}#if end}#if end#儲存每個要執行的程式資訊$process=array();#debug#var_dump(__LINE__,$executeBys);#針對每個指令與參數字串foreach($conf["cmds"] as $index=>$cmdAndArguStr){#debug#var_dump(__LINE__,$executeBys[$index]);#運行 php 程式,並儲存 resource$process[$index]["resource"] = proc_open($executeBys[$index], $descriptorspec, $pipes, $cwds[$index], $envs[$index]);#儲存對應的 pipes$process[$index]["pipes"]=$pipes;#如果有成功執行if(is_resource($process[$index]["resource"])){#$pipes now looks like this:#0 => writeable handle connected to child stdin#1 => readable handle connected to child stdout#2 => readable handle connected to child stdin#寫入內容作為 $executeBy 的輸入$bytes2write=fwrite($process[$index]["pipes"][0], $cmdAndArguStr);#結束輸入fclose($process[$index]["pipes"][0]);#如果有完整寫入指令if($bytes2write===strlen($cmdAndArguStr)){#記錄輸入的指令$process[$index]["input"]=$cmdAndArguStr;}#if end#反之else{#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"][]="將指令(".$cmdAndArguStr.")輸入(".$executeBys[$index].")失敗";#回傳結果return $result;}#else end}#if end#反之,代表運行 $executeBys[$index] 失敗else{#初始化暫存執行結果的變數$cmdRes=array();#設置執行失敗$cmdRes["status"]="false";#設置執行錯誤訊息$cmdRes["error"]="execute program by \"".$executeBys[$index]."\" failed!";#設置執行結果$result["content"][]=$cmdRes;}#else end}#foreach end#針對每個回饋foreach($process as $index => $ps){#取得 proc resource$resource=&$ps["resource"];#取得標準輸出的pipe$stdout=$process[$index]["pipes"][1];#取得非標準輸出的pipe$stderr=$process[$index]["pipes"][2];#如果需要等待程序執行完if($conf["wait"]==="true"){#如果有設置 timeoutif(isset($conf["timeout"])){#如果有設置該程序的 timeoutif(isset($conf["timeout"][$index])){#避免 timeout 仍然會等待程序結束 - start#不讓標準輸出會阻擋程式執行stream_set_blocking($stdout,false);#不讓錯誤輸出會阻擋程式執行stream_set_blocking($stderr,false);#避免 timeout 仍然會等待程序結束 - end}#if end}#if end}#if end#反之else{#不讓標準輸出會阻擋程式執行stream_set_blocking($stdout,false);#不讓錯誤輸出會阻擋程式執行stream_set_blocking($stderr,false);}#else end#初始化暫存執行狀況的變數$cmdRes=array();#取得 proc_open 後的 process resource$cmdRes["process"]=$resource;#取得 process 的狀態,包含 pid 等資訊,若程式已經結束,則會自動將pipes關閉,再proc_close.$cmdRes["proc_get_status"]=proc_get_status($resource);#預設 statusCode 為 "?" 代表尚未 proc_close$cmdRes["statusCode"]="?";#如果執行已經結束,有回傳exitcodeif($cmdRes["proc_get_status"]["exitcode"]!==-1){#設置 statusCode$cmdRes["statusCode"]=&$cmdRes["proc_get_status"]["exitcode"];}#if end#反之未執行完畢,且需要等待程序執行完else if($conf["wait"]==="true"){#預設已經執行0秒$runtime=0;#無窮迴圈while(true){#debug#var_dump(__LINE__,$runtime,$conf["timeout"]);#如果有設置 timeoutif(isset($conf["timeout"])){#如果有設置該程序的 timeoutif(isset($conf["timeout"][$index])){#如果執行秒數逾時了if( $runtime > (int)($conf["timeout"][$index]) ){#debug#var_dump(__LINE__,"timeout!");#關閉標準輸出的pipefclose($stdout);#關閉標準錯誤的pipefclose($stderr);#強制結束程序proc_terminate($resource);#結束proc.proc_close($resource);#結束無窮迴圈break;}#if end}#if end}#if end#取得 process 的狀態,包含 pid 等資訊,若程式已經結束,則會自動將pipes關閉,再proc_close.$cmdRes["proc_get_status"]=proc_get_status($resource);#如果執行已經結束,有回傳exitcodeif($cmdRes["proc_get_status"]["exitcode"]!==-1){#設置 statusCode$cmdRes["statusCode"]=&$cmdRes["proc_get_status"]["exitcode"];#結束無窮迴圈break;}#if end#等待1秒鐘sleep(1);#執行秒數+1$runtime++;}#while end}#if end#設置執行失敗訊息$cmdRes["error"]=$stderr;#設置執行結果$cmdRes["content"]=$stdout;#如果有成功輸入指令if(isset($process[$index]["input"])){#設置有輸入的指令$cmdRes["input"]=$process[$index]["input"];}#if end#預設執行不正常$cmdRes["status"]="false";#如果執行正常 或 等於"?"(代表尚未 proc_close)if($cmdRes["statusCode"]===0 || $cmdRes["statusCode"]==="?"){#設置執行正常$cmdRes["status"]="true";}#if end#保存結果$result["content"][]=$cmdRes;}#foreach end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function proc end/*#函式說明:#更新透過proc執行的多程序資訊.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$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"代表程序的資訊.#必填參數:#$conf["procs"],陣列,運行self::proc後回傳的content.$conf["procs"]=$procs;#可省略參數:#無.#參考資料:#無.#備註:#無.*/public static function proc_update(&$conf){#初始化要回傳的變數$result=array();#初始化當前執行的函數名稱$result["function"]=__FUNCTION__;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#取得使用的參數$result["argu"]=$conf;#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],執行不正常結束的錯訊息陣列.#$result["simpleError"],簡單表示的錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可省略參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("procs");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("procs");#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("wait","workingDir","envs","executeBy");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("wait","workingDir","envs","executeBy");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","array","array");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true",null,null,null);#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".#$conf["disallowAllSkipableVarNotExist"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("");#參考資料:#array_keys=>http://php.net/manual/en/function.array-keys.php#備註:#無.$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果 $checkArguments["status"] 等於 "false"if($checkArguments["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果 $checkArguments["passed"] 等於 "false"if($checkArguments["passed"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#檢查 content/*#$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"代表程序的資訊.*/#針對每個程序foreach($conf["procs"] as $index => $proc){#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],執行不正常結束的錯訊息陣列.#$result["simpleError"],簡單表示的錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$proc;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可省略參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("status","statusCode","content","error","input","process","proc_get_status");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string",null,null,null,"string","resource","array");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("procs");#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["variableCheck::checkArguments"]["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("wait","workingDir","envs","executeBy");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("error");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true",null,null,null);#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".#$conf["disallowAllSkipableVarNotExist"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("");#參考資料:#array_keys=>http://php.net/manual/en/function.array-keys.php#備註:#無.$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果 $checkArguments["status"] 等於 "false"if($checkArguments["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果 $checkArguments["passed"] 等於 "false"if($checkArguments["passed"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果可能尚在執行中if($proc["statusCode"]==="?"){#取得當下的狀態$proc_get_status=proc_get_status($proc["process"]);#如果執行已經結束,有回傳exitcodeif($proc_get_status["exitcode"]!==-1){#設置 statusCode$conf["procs"][$index]["statusCode"]=$proc_get_status["exitcode"];#取得標準輸出$stdout=stream_get_contents($proc["content"]);#取得錯誤輸出$stderr=stream_get_contents($proc["error"]);#設置執行失敗訊息$conf["procs"][$index]["error"]=$stderr;#設置執行結果$conf["procs"][$index]["content"]=$stdout;}#if end}#if end}#foreach end#設置要回傳的結果$result["content"]=$conf["procs"];#設置執行正常$result["status"]="true";#回傳結果return $result;}#function proc_update end/*#函式說明:#透過parallel展示多執行序運作.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#無.#可省略參數:#無.#參考資料:#https://www.php.net/manual/en/class.parallel-runtime.php#備註:#需要於編譯PHP時啟用該套件*/public static function parallel_demo(){#初始化要回傳的結果$result=array();#取得當前執行的函數名稱$result["function"]=__FUNCTION__;#新增程序r1$r1=new \parallel\Runtime();#r1要執行的函式$thread_r1_function=function($conf){#提示開始echo $conf["id"]." start".PHP_EOL;#跑 $conf["i"] 次for($i=0;$i<$conf["i"];$i++){#題書$i數值echo "\$i=".$i.PHP_EOL;}#for end#提示結束echo $conf["id"]." end".PHP_EOL;};#function end#r1的參數$args_r1=array();$args_r1["id"]="r1";$args_r1["i"]=10;#運行程序r1#程序函式為 $thread_r1_function#參數陣列為 $args_r1$future_r1=$r1->run($thread_r1_function, $args_r1);#新增程序r2$r2=new \parallel\Runtime();#r2要執行的函式$thread_r2_function=function($conf){#提示開始echo $conf["id"]." start".PHP_EOL;#跑 $conf["i"] 次for($i=$conf["i"];$i>0;$i--){#題書$i數值echo "\$i=".$i.PHP_EOL;}#for end#提示結束echo $conf["id"]." end".PHP_EOL;};#function end#r2的參數$args_r2=array();$args_r2["id"]="r2";$args_r2["i"]=10;#運行程序r2#程序函式為 $thread__r2_function#參數陣列為 $args_r2$future_r2=$r2->run($thread_r2_function, $args_r2);#存放有多少在執行的程序$futureArray=array();$futureArray[]=$future_r1;$futureArray[]=$future_r2;#當有程序尚未結束時while(!empty($futureArray)){#針對每個 Futureforeach($futureArray as $index => $Future){#如果執行完成了if($Future->done()){#移除之unset($futureArray[$index]);}#if end}#foreach end}#while end#提示所有程序都執行結束了echo "all done!".PHP_EOL;#設置執行正常$result["status"]="true";#回傳結果return $result;}#function parallel_demo end/*#函式說明:#透過 unix socket 來多執行序運作.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["content"],陣列,每個元素為cmds參數中個別元素其指令傳送後得到的uuid,可透過sock::getProcInfo來查詢結果.#必填參數:#$conf["cmds"],字串陣列,每個元素代表要執行的指令與參數.#$conf["cmds"]=array();#可省略參數:#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.#$conf["sock"]=qbpwcf_usock_path;#參考資料:#無#備註:#需要透過sock::unixDomainSockServer來運行.*/public static function socket(&$conf){#初始化要回傳的變數$result=array();#初始化當前執行的函數名稱$result["function"]=__FUNCTION__;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#取得使用的參數$result["argu"]=$conf;#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],執行不正常結束的錯訊息陣列.#$result["simpleError"],簡單表示的錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["argu"],設置給予的參數.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可省略參數:#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cmds");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.#$conf["canNotBeEmpty"]=array();#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sock");#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sock");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmpty"]="";#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".#$conf["disallowAllSkipableVarIsEmptyArray"]="";#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".#$conf["disallowAllSkipableVarNotExist"]="";#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("");#參考資料:#array_keys=>http://php.net/manual/en/function.array-keys.php#備註:#無.$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果 $checkArguments["status"] 等於 "false"if($checkArguments["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果 $checkArguments["passed"] 等於 "false"if($checkArguments["passed"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#針對每個指令foreach($conf["cmds"] as $cmd){#連線到 usr/bin/qbpwcf-usock.php 產生的 unix domain socket,運行指定的指令.#回傳結果:#$result["status"],"true"代表執行正常;"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["content"],執行完指令的結果.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;#$conf["command"],字串,要執行的指令名稱.$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]=$cmd;#可省略參數:#如果有設置 sock 參數if(isset($conf["sock"])){#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.$conf["sock::execAnyCmdByQBPWCFunixSocket"]["sock"]=$conf["sock"];}#if end#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=$conf["argu"];#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandInBg"]="true";#參考資料:#無.#備註:#無.$execAnyCmdByQBPWCFunixSocket=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);#如果執行失敗if($execAnyCmdByQBPWCFunixSocket["status"]==="false"){#設置錯誤識別$result["status"]="false";#設置錯誤訊息$result["error"]=$execAnyCmdByQBPWCFunixSocket;#回傳結果return $result;}#if end#debug#var_dump(__LINE__,$execAnyCmdByQBPWCFunixSocket);#儲存收到的回應$result["content"][]=$execAnyCmdByQBPWCFunixSocket["content"];}#foreach end#設置執行正常$result["status"]="true";#回傳結果return $result;}#function socket end}#class threads end