Subversion Repositories php-qbpwcf

Rev

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

Rev 3 Rev 226
Line 1... Line 1...
1
#!/usr/bin/php
1
#!/usr/bin/php
2
<?php
2
<?php
3
 
3
 
4
/*
4
/*
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2015~2024 Min-Jhin,Chen
6
    Copyright (C) 2014~2025 MIN ZHI, CHEN
7
 
7
 
8
    This file is part of QBPWCF.
8
    This file is part of QBPWCF.
9
 
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
11
    it under the terms of the GNU General Public License as published by
Line 17... Line 17...
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
18
    GNU General Public License for more details.
19
 
19
 
20
    You should have received a copy of the GNU General Public License
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
    
22
 
23
*/
23
*/
24
 
24
 
25
/*
25
/*
26
說明:
26
說明:
27
啟動 用來接收 request 來跟 web socket server 互動.
27
啟動 用來接收 request 來跟 web socket server 互動.
Line 63... Line 63...
63
	#結束執行,回傳shell 1.
63
	#結束執行,回傳shell 1.
64
	exit(1);
64
	exit(1);
65
 
65
 
66
	}#if end
66
	}#if end
67
 
67
 
68
#設置 include path 
68
#設置 include path
69
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
69
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
70
 
70
 
71
#匯入外部套件
71
#匯入外部套件
72
include("allInOne.php");
72
include("allInOne.php");
73
 
73
 
74
#說明函式
74
#說明函式
75
function help()
75
function help()
76
{
76
{
77
	#印出指令說明
77
	#印出指令說明
78
	echo "Usage of ".basename(__FILE__).":".PHP_EOL; 
78
	echo "Usage of ".basename(__FILE__).":".PHP_EOL;
79
	echo "--domain 代表要連線的 web socket 服務域名".PHP_EOL;
79
	echo "--domain 代表要連線的 web socket 服務域名".PHP_EOL;
80
	echo "--path 代表要連線的 web socket 服務path,預設為 wss".PHP_EOL;
80
	echo "--path 代表要連線的 web socket 服務path,預設為 wss".PHP_EOL;
81
	echo "--port 代表要連線的 web socket 服務port,預設為 443".PHP_EOL;
81
	echo "--port 代表要連線的 web socket 服務port,預設為 443".PHP_EOL;
82
	
82
 
83
	#結束執行
83
	#結束執行
84
	exit;
84
	exit;
85
}
85
}
86
 
86
 
87
#函式說明:
87
#函式說明:
Line 108... Line 108...
108
#如果解析參數失敗
108
#如果解析參數失敗
109
if($parseArgu["status"]==="false")
109
if($parseArgu["status"]==="false")
110
{
110
{
111
	#印出結果
111
	#印出結果
112
	var_dump($parseArgu);
112
	var_dump($parseArgu);
113
	
113
 
114
	#結束執行,回傳shell 1
114
	#結束執行,回傳shell 1
115
	exit(1);
115
	exit(1);
116
	
116
 
117
}#if end
117
}#if end
118
 
118
 
119
#檢查參數
119
#檢查參數
120
#函式說明:
120
#函式說明:
121
#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
121
#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
Line 168... Line 168...
168
#若執行失敗
168
#若執行失敗
169
if($checkArguments["status"]==="false"){
169
if($checkArguments["status"]==="false"){
170
 
170
 
171
	#印出結果
171
	#印出結果
172
	var_dump($checkArguments);
172
	var_dump($checkArguments);
173
	
173
 
174
	#結束執行,回傳shell 1
174
	#結束執行,回傳shell 1
175
	exit(1);
175
	exit(1);
176
 
176
 
177
	}#if end
177
	}#if end
178
 
178
 
179
#若檢查不通過
179
#若檢查不通過
180
if($checkArguments["passed"]==="false"){
180
if($checkArguments["passed"]==="false"){
181
 
181
 
182
	#印出結果
182
	#印出結果
183
	var_dump($checkArguments);
183
	var_dump($checkArguments);
184
	
184
 
185
	#結束執行,回傳shell 1
185
	#結束執行,回傳shell 1
186
	exit(1);
186
	exit(1);
187
 
187
 
188
	}#if end
188
	}#if end
189
 
189
 
Line 243... Line 243...
243
	#等待1毫秒
243
	#等待1毫秒
244
	usleep(100000);
244
	usleep(100000);
245
 
245
 
246
	#針對每個程序
246
	#針對每個程序
247
	foreach($proc["content"] as $index=>$process){
247
	foreach($proc["content"] as $index=>$process){
248
	
248
 
249
		#如果程序執行異常
249
		#如果程序執行異常
250
		if($process["status"]==="false"){
250
		if($process["status"]==="false"){
251
		
251
 
252
			#debug
252
			#debug
253
			var_dump($proc);
253
			var_dump($proc);
254
		
254
 
255
			#移除該程序資訊
255
			#移除該程序資訊
256
			unset($proc["content"][$index]);
256
			unset($proc["content"][$index]);
257
		
257
 
258
			}#if end
258
			}#if end
259
			
259
 
260
		#如果是 resource
260
		#如果是 resource
261
		if(is_resource($process["process"])){
261
		if(is_resource($process["process"])){
262
		
262
 
263
			#如果error為resource
263
			#如果error為resource
264
			if(is_resource($process["error"])){
264
			if(is_resource($process["error"])){
265
			
265
 
266
				#將建立的 listen sock 放到 $master 陣列
266
				#將建立的 listen sock 放到 $master 陣列
267
				$master[] = $process["error"];
267
				$master[] = $process["error"];
268
			
268
 
269
				#設置給 stream_select 監控的sock變數
269
				#設置給 stream_select 監控的sock變數
270
				$read = $write = $except = $master;
270
				$read = $write = $except = $master;
271
				
271
 
272
				#等待0.1秒,看有沒有讀寫的狀況
272
				#等待0.1秒,看有沒有讀寫的狀況
273
				$mod_fd = stream_select($read, $write, $except, 1);
273
				$mod_fd = stream_select($read, $write, $except, 1);
274
			
274
 
275
				#如果偵測異動失敗
275
				#如果偵測異動失敗
276
				if($mod_fd===FALSE){
276
				if($mod_fd===FALSE){
277
					
277
 
278
					#monitior stream failed
278
					#monitior stream failed
279
					
279
 
280
					#debug
280
					#debug
281
					var_dump($proc);
281
					var_dump($proc);
282
					
282
 
283
					#結束執行,回傳shell 1
283
					#結束執行,回傳shell 1
284
					exit(1);
284
					exit(1);
285
					
285
 
286
					}#if end
286
					}#if end
287
					
287
 
288
				#如果有異動的跡象
288
				#如果有異動的跡象
289
				else if($mod_fd>0){
289
				else if($mod_fd>0){
290
	
290
 
291
					#針對每個異動的 stream
291
					#針對每個異動的 stream
292
					foreach($read as $readStream){
292
					foreach($read as $readStream){
293
					
293
 
294
						#如果是有錯誤輸出
294
						#如果是有錯誤輸出
295
						if($readStream===$process["error"]){
295
						if($readStream===$process["error"]){
296
						
296
 
297
							#debug
297
							#debug
298
							#echo "try read std error output".PHP_EOL;
298
							#echo "try read std error output".PHP_EOL;
299
						
299
 
300
							#讀取1Kbyte
300
							#讀取1Kbyte
301
							$errorByte=fread($process["error"],1024);
301
							$errorByte=fread($process["error"],1024);
302
						
302
 
303
							#提示為錯誤訊息
303
							#提示為錯誤訊息
304
							echo "error:";
304
							echo "error:";
305
								
305
 
306
							#印出內容
306
							#印出內容
307
							echo $errorByte;
307
							echo $errorByte;
308
							
308
 
309
							#換行
309
							#換行
310
							echo PHP_EOL;
310
							echo PHP_EOL;
311
						
311
 
312
							}#if end
312
							}#if end
313
					
313
 
314
						}#foreach end
314
						}#foreach end
315
					
315
 
316
					}#if end
316
					}#if end
317
					
317
 
318
				}#if end
318
				}#if end
319
				
319
 
320
			#如果content為resource
320
			#如果content為resource
321
			if(is_resource($process["content"])){
321
			if(is_resource($process["content"])){
322
			
322
 
323
				#將建立的 listen sock 放到 $master 陣列
323
				#將建立的 listen sock 放到 $master 陣列
324
				$master[] = $process["content"];
324
				$master[] = $process["content"];
325
			
325
 
326
				#設置給 stream_select 監控的sock變數
326
				#設置給 stream_select 監控的sock變數
327
				$read = $write = $except = $master;
327
				$read = $write = $except = $master;
328
				
328
 
329
				#等待1秒,看有沒有讀寫的狀況
329
				#等待1秒,看有沒有讀寫的狀況
330
				$mod_fd = stream_select($read, $write, $except, 1);
330
				$mod_fd = stream_select($read, $write, $except, 1);
331
			
331
 
332
				#如果偵測異動失敗
332
				#如果偵測異動失敗
333
				if($mod_fd===FALSE){
333
				if($mod_fd===FALSE){
334
					
334
 
335
					#monitior stream failed
335
					#monitior stream failed
336
					
336
 
337
					#debug
337
					#debug
338
					var_dump($proc);
338
					var_dump($proc);
339
					
339
 
340
					#結束執行,回傳shell 1
340
					#結束執行,回傳shell 1
341
					exit(1);
341
					exit(1);
342
					
342
 
343
					}#if end
343
					}#if end
344
					
344
 
345
				#如果有異動的跡象
345
				#如果有異動的跡象
346
				else if($mod_fd>0){
346
				else if($mod_fd>0){
347
				
347
 
348
					#針對每個異動的 stream
348
					#針對每個異動的 stream
349
					foreach($read as $readStream){
349
					foreach($read as $readStream){
350
					
350
 
351
						#如果是有標準輸出
351
						#如果是有標準輸出
352
						if($readStream===$process["content"]){
352
						if($readStream===$process["content"]){
353
					
353
 
354
							#debug
354
							#debug
355
							#echo "try read std output".PHP_EOL;
355
							#echo "try read std output".PHP_EOL;
356
						
356
 
357
							#不讓標準輸出會阻擋程式執行
357
							#不讓標準輸出會阻擋程式執行
358
							#stream_set_blocking($process["content"],false);
358
							#stream_set_blocking($process["content"],false);
359
						
359
 
360
							#讀取1Kbyte
360
							#讀取1Kbyte
361
							$contentByte=fread($process["content"],1024);
361
							$contentByte=fread($process["content"],1024);
362
					
362
 
363
							#如果有資料
363
							#如果有資料
364
							if(strlen($contentByte)>0){
364
							if(strlen($contentByte)>0){
365
							
365
 
366
								#如果有關鍵字
366
								#如果有關鍵字
367
								if(strpos($contentByte,"unixDomainSocket:")===0){
367
								if(strpos($contentByte,"unixDomainSocket:")===0){
368
																	
-
 
-
 
368
 
369
									#函式說明:
369
									#函式說明:
370
									#將固定格式的字串分開,並回傳分開的結果.
370
									#將固定格式的字串分開,並回傳分開的結果.
371
									#回傳結果:
371
									#回傳結果:
372
									#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
372
									#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
373
									#$result["error"],錯誤訊息陣列
373
									#$result["error"],錯誤訊息陣列
Line 389... Line 389...
389
									#無.
389
									#無.
390
									#備註:
390
									#備註:
391
									#無.
391
									#無.
392
									$spiltString=stringProcess::spiltString($conf);
392
									$spiltString=stringProcess::spiltString($conf);
393
									unset($conf);
393
									unset($conf);
394
								
394
 
395
									#debug
395
									#debug
396
									#var_dump(__LINE__,$spiltString);
396
									#var_dump(__LINE__,$spiltString);
397
								
397
 
398
									#如果執行失敗
398
									#如果執行失敗
399
									if($spiltString["status"]==="false"){
399
									if($spiltString["status"]==="false"){
400
										
400
 
401
										#debug
401
										#debug
402
										var_dump($spiltString);
402
										var_dump($spiltString);
403
										
403
 
404
										#結束執行,回傳shell 1
404
										#結束執行,回傳shell 1
405
										exit(1);
405
										exit(1);
406
										
406
 
407
										}#if end
407
										}#if end
408
										
408
 
409
									#如果有分割用的關鍵字
409
									#如果有分割用的關鍵字
410
									if($spiltString["found"]==="true"){
410
									if($spiltString["found"]==="true"){
411
										
411
 
412
										#如果分割出來的數量為1
412
										#如果分割出來的數量為1
413
										if($spiltString["dataCounts"]===1){
413
										if($spiltString["dataCounts"]===1){
414
										
414
 
415
											#取得 unix doamin socket 的位置
415
											#取得 unix doamin socket 的位置
416
											$unixDomainSocket=$spiltString["dataArray"][0];
416
											$unixDomainSocket=$spiltString["dataArray"][0];
417
										
417
 
418
											#提示透過 unix domain socket 來傳接收要做的事情
418
											#提示透過 unix domain socket 來傳接收要做的事情
419
											echo "Using unix domain socket:".$unixDomainSocket." 來跟 web socket server 互動".PHP_EOL;
419
											echo "Using unix domain socket:".$unixDomainSocket." 來跟 web socket server 互動".PHP_EOL;
420
											
420
 
421
											#後面忽略,換下一個
421
											#後面忽略,換下一個
422
											continue;
422
											continue;
423
											
423
 
424
											}#if end	
424
											}#if end
425
										
425
 
426
										}#if end
426
										}#if end
427
								
427
 
428
									}#if end
428
									}#if end
429
							
429
 
430
								#印出內容
430
								#印出內容
431
								echo $contentByte;
431
								echo $contentByte;
432
							
432
 
433
								#換行
433
								#換行
434
								echo PHP_EOL;
434
								echo PHP_EOL;
435
							
435
 
436
								}#if end
436
								}#if end
437
							
437
 
438
							}#if end
438
							}#if end
439
					
439
 
440
						}#foreach end
440
						}#foreach end
441
					
441
 
442
					}#if end
442
					}#if end
443
					
443
 
444
					#反之代表沒有任何輸出
444
					#反之代表沒有任何輸出
445
					else{
445
					else{
446
					
446
 
447
						#提示在等待任何輸出
447
						#提示在等待任何輸出
448
						echo ".";
448
						echo ".";
449
					
449
 
450
						}#else end
450
						}#else end
451
					
451
 
452
				}#if end
452
				}#if end
453
		
453
 
454
			#如果已經結束執行
454
			#如果已經結束執行
455
			if($process["proc_get_status"]["running"]==="false"){
455
			if($process["proc_get_status"]["running"]==="false"){
456
			
456
 
457
				#移除該程序資訊
457
				#移除該程序資訊
458
				unset($proc["content"][$index]);
458
				unset($proc["content"][$index]);
459
			
459
 
460
				}#if end
460
				}#if end
461
				
461
 
462
			#反之
462
			#反之
463
			else{
463
			else{
464
			
464
 
465
				#更新 "proc_get_status"
465
				#更新 "proc_get_status"
466
				$proc["content"][$index]["proc_get_status"]=proc_get_status($process["process"]);
466
				$proc["content"][$index]["proc_get_status"]=proc_get_status($process["process"]);
467
			
467
 
468
				}#else end
468
				}#else end
469
		
469
 
470
			}#if end
470
			}#if end
471
	
471
 
472
		#反之
472
		#反之
473
		else{
473
		else{
474
		
474
 
475
			#移除該程序資訊
475
			#移除該程序資訊
476
			unset($proc["content"][$index]);
476
			unset($proc["content"][$index]);
477
		
477
 
478
			}#else end
478
			}#else end
479
	
479
 
480
		}#foreach end
480
		}#foreach end
481
 
481
 
482
	}#while end
-
 
483
482
	}#while end
-
 
483