Subversion Repositories php-qbpwcf

Rev

Rev 239 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 239 Rev 249
Line 340... Line 340...
340
	#參考資料:
340
	#參考資料:
341
	#https://www.php.net/manual/en/function.proc-open.php
341
	#https://www.php.net/manual/en/function.proc-open.php
342
	#https://www.php.net/manual/en/function.proc-get-status.php
342
	#https://www.php.net/manual/en/function.proc-get-status.php
343
	#https://www.php.net/manual/en/function.proc-terminate.php
343
	#https://www.php.net/manual/en/function.proc-terminate.php
344
	#備註:
344
	#備註:
-
 
345
	#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
345
	#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
346
	#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
346
	*/
347
	*/
347
	public static function proc(&$conf){
348
	public static function proc(&$conf){
348
 
349
 
349
		#初始化要回傳的變數
350
		#初始化要回傳的變數
350
		$result=array();
351
		$result=array();
Line 765... Line 766...
765
					#如果執行已經結束,有回傳exitcode
766
					#如果執行已經結束,有回傳exitcode
766
					if($cmdRes["proc_get_status"]["exitcode"]!==-1){
767
					if($cmdRes["proc_get_status"]["exitcode"]!==-1){
767
 
768
 
768
						#設置 statusCode
769
						#設置 statusCode
769
						$cmdRes["statusCode"]=&$cmdRes["proc_get_status"]["exitcode"];
770
						$cmdRes["statusCode"]=&$cmdRes["proc_get_status"]["exitcode"];
770
 
771
	
771
						#結束無窮迴圈
772
						#結束無窮迴圈
772
						break;
773
						break;
773
 
774
 
774
						}#if end
775
						}#if end
775
 
776
 
Line 811... Line 812...
811
			#保存結果
812
			#保存結果
812
			$result["content"][]=$cmdRes;
813
			$result["content"][]=$cmdRes;
813
 
814
 
814
			}#foreach end
815
			}#foreach end
815
 
816
 
-
 
817
		#如果要等待程序執行結束
-
 
818
		if($conf["wait"]==="true"){
-
 
819
 
-
 
820
			#函式說明:
-
 
821
			#更新透過proc執行的多程序資訊.
-
 
822
			#回傳結果:
-
 
823
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
824
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
825
			#$result["function"],當前執行的函式名稱.
-
 
826
			#$result["argu"],使用的參數.
-
 
827
			#$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"代表程序的資訊.
-
 
828
			#必填參數:
-
 
829
			#$conf["procs"],陣列,運行self::proc後回傳的content.
-
 
830
			$conf["threads::proc_update"]["procs"]=$result["content"];
-
 
831
			#可省略參數:
-
 
832
			#無.
-
 
833
			#參考資料:
-
 
834
			#無.
-
 
835
			#備註:
-
 
836
			#無.
-
 
837
			$proc_update=threads::proc_update($conf["threads::proc_update"]);
-
 
838
			unset($conf["threads::proc_update"]);
-
 
839
 
-
 
840
			#如果執行異常
-
 
841
			if($proc_update["status"]==="false"){
-
 
842
 
-
 
843
				#設置錯誤識別
-
 
844
				$result["status"]="false";
-
 
845
 
-
 
846
				#設置錯誤訊息
-
 
847
				$result["error"]=$proc_update;
-
 
848
 
-
 
849
				#回傳結果
-
 
850
				return $result;
-
 
851
 
-
 
852
				}#if end
-
 
853
 
-
 
854
			#debug
-
 
855
			#var_dump(__LINE__,$proc_update);exit;
-
 
856
 
-
 
857
			#取得執行後的標準輸出
-
 
858
			$result["content"]=$proc_update["content"];
-
 
859
 
-
 
860
			}#if end
-
 
861
 
816
		#設置執行正常
862
		#設置執行正常
817
		$result["status"]="true";
863
		$result["status"]="true";
818
 
864
 
819
		#回傳結果
865
		#回傳結果
820
		return $result;
866
		return $result;
Line 1072... Line 1118...
1072
					$conf["procs"][$index]["content"]=$stdout;
1118
					$conf["procs"][$index]["content"]=$stdout;
1073
 
1119
 
1074
					}#if end
1120
					}#if end
1075
 
1121
 
1076
				}#if end
1122
				}#if end
-
 
1123
			
-
 
1124
			#反之已經執行完畢
-
 
1125
			else{
-
 
1126
			
-
 
1127
				#如果標準輸出依然為 resource
-
 
1128
				if(gettype($proc["content"])==="resource"){
-
 
1129
				
-
 
1130
					#取得標準輸出
-
 
1131
					$stdout=stream_get_contents($proc["content"]);
-
 
1132
 
-
 
1133
					#設置執行結果
-
 
1134
					$conf["procs"][$index]["content"]=$stdout;
-
 
1135
					
-
 
1136
					}#if end
-
 
1137
					
-
 
1138
				#如果錯誤輸出依然為 resource
-
 
1139
				if(gettype($proc["error"])==="resource"){
-
 
1140
				
-
 
1141
					#取得錯誤輸出
-
 
1142
					$stderr=stream_get_contents($proc["error"]);
-
 
1143
					
-
 
1144
					#設置執行失敗訊息
-
 
1145
					$conf["procs"][$index]["error"]=$stderr;
-
 
1146
				
-
 
1147
					}#if end
-
 
1148
			
-
 
1149
				}#else end
1077
 
1150
 
1078
			}#foreach end
1151
			}#foreach end
1079
 
1152
 
1080
		#設置要回傳的結果
1153
		#設置要回傳的結果
1081
		$result["content"]=$conf["procs"];
1154
		$result["content"]=$conf["procs"];