Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14 liveuser 1
#!/usr/bin/php
2
<?php
3
 
4
#使用命名空間
5
namespace qbpwcf;
6
 
7
#匯入外部套件
8
include("../allInOne.php");
9
 
10
/*
11
 
12
#提示目前要測試的套件
13
echo "<hr>webSock::registerChatDemo - testCase 1<br>";
14
 
15
#涵式說明:
16
#註冊聊天室範例的 passProxy 設定,本函數會用root帳戶去新增.
17
#會在 /etc/httpd/conf/httpd.conf 檔案裡面加上以下內容
18
##Enable the mod_proxy modules in the HTTPD
19
#LoadModule proxy_module modules/mod_proxy.so
20
#LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
21
#
22
##ProxyPass
23
##If requeted web address is begin with (ws://hostdns)/wss/chatDemo, then redirect to ws://localhost:8080
24
#ProxyPass /wss/chatDemo ws://localhost:8080
25
#回傳結果:
26
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27
#$reuslt["error"],執行不正常結束的錯訊息陣列.
28
#$result["function"],當前執行的函式名稱.
29
#必填參數:
30
#$conf["fileArgu"],字串,__FILE__的內容.
31
$conf["fileArgu"]=__FILE__;
32
#可省略參數:
33
#$conf["rootPasswd"],字串,root帳戶的密碼,預設為"password".
34
#$conf["rootPasswd"]="password";
35
#$conf["httpd.conf"],字串,apache設定檔的路徑與名稱,預設為"/etc/httpd/conf/httpd.conf".
36
#$conf["httpd.conf"]="/etc/httpd/conf/httpd.conf";
37
#備註:
38
#僅能在命令列環境下執行.
39
#參考資料:
40
#用apache的passProxy來識別服務並轉到正確的port=>https://groups.google.com/forum/#!topic/ratchet-php/dj-PgPPO_J0
41
$registerChatDemo=webSock::registerChatDemo($conf);
42
unset($conf);
43
 
44
#如果聊天室範例的 passProxy 設定失敗
45
if($registerChatDemo["status"]==="false"){
46
 
47
	#印出訊息
48
	var_dump($registerChatDemo);
49
 
50
	#結束程式
51
	exit;
52
 
53
	}#if end
54
 
55
*/
56
 
57
/*
58
 
59
#提示目前要測試的套件
60
echo "<hr>webSock::chatRoomDemo - testCase 1<br>";
61
 
62
#設置資料庫連線密碼
63
Chat::$dbPassword=$dbPassword;
64
 
65
#不使用密碼來驗證身份
66
Chat::$passwordCol="";
67
 
68
#函數說明:
69
#Ratchet的聊天室伺服端範例,port為8080.
70
#回傳結果:
71
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
72
#$reuslt["error"],執行不正常結束的錯訊息陣列.
73
#$result["function"],當前執行的函式名稱.		
74
#必填參數:
75
#$conf["fileArgu"],字串,__FILE__的內容.
76
$conf["fileArgu"]=__FILE__;
77
#$conf["disReg"],字串,是否要取消apache的passProxy檢查與設定,預設為"false"不取消,"true"為取消.
78
$conf["disReg"]="true";
79
#參考資料:
80
#Ratchet官網=>http://socketo.me/
81
#聊天室範例=>http://socketo.me/docs/hello-world
82
#備註:
83
#必須要在命令列環境下執行一次,建立webSocket Server後,再於網頁端執行即可產生webSocket Client端的code.
84
#僅適用於http網頁透過ws連線到web socket server.
85
$chatRoomDemo=webSock::chatRoomDemo($conf);
86
unset($conf);
87
 
88
#如果執行失敗
89
if($chatRoomDemo["status"]==="false"){
90
 
91
	#印出結果
92
	var_dump($chatRoomDemo);
93
 
94
	#結束程式
95
	exit;
96
 
97
	}#if end
98
 
99
#如果存在 $chatRoomDemo["content"] 則查看結果
100
if(isset($chatRoomDemo["content"])){
101
 
102
	#印出語法
103
	echo $chatRoomDemo["content"];
104
 
105
	}#if end
106
 
107
*/	
108
 
109
/*
110
 
111
#提示目前要測試的套件
112
echo "<hr>webSock::chatRoomDemo - testCase 2<br>";
113
 
114
#設置資料庫連線密碼
115
ChatV2::$dbPassword=$dbPassword;
116
 
117
#不使用密碼來驗證身份
118
ChatV2::$passwordCol="password";
119
 
120
#函數說明:
121
#擴充過的Ratchet的聊天室用戶端與伺服端範例第二版,port為8080.
122
#回傳結果:
123
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
124
#$reuslt["error"],執行不正常結束的錯訊息陣列.
125
#$result["function"],當前執行的函式名稱.		
126
#必填參數:
127
#$conf["fileArgu"],字串,__FILE__的內容.
128
$conf["fileArgu"]=__FILE__;
129
#可省略參數:
130
#$conf["disReg"],字串,是否要取消apache的passProxy檢查與設定,預設為"false"不取消,"true"為取消.
131
$conf["disReg"]="true";
132
#參考資料:
133
#Ratchet官網=>http://socketo.me/
134
#聊天室範例=>http://socketo.me/docs/hello-world
135
#備註:
136
#必須要在命令列環境下執行一次,建立webSocket Server後,再於網頁端執行即可產生webSocket Client端的code.
137
#僅適用於http網頁透過ws連線到web socket server.
138
$chatRoomDemoV2=webSock::chatRoomDemoV2($conf);
139
unset($conf);
140
 
141
#如果執行失敗
142
if($chatRoomDemoV2["status"]==="false"){
143
 
144
	#印出結果
145
	var_dump($chatRoomDemoV2);
146
 
147
	#結束程式
148
	exit;
149
 
150
	}#if end
151
 
152
#如果存在 $chatRoomDemoV2["content"] 則查看結果
153
if(isset($chatRoomDemoV2["content"])){
154
 
155
	#印出語法
156
	echo $chatRoomDemoV2["content"];
157
 
158
	}#if end
159
 
160
*/	
161
 
162
/*	
163
 
164
#提示目前要測試的套件
165
echo "<hr>webSock::nativeSocketTcpipServer - testCase 1<br>";	
166
 
167
#函式說明:
168
#建立php原生的socket
169
#回傳結果:
170
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
171
#$result["error"],錯誤訊息陣列.
172
#$resutl["function"],當前執行的涵式名稱.
173
#$result["argu"],所使用的參數.
174
#必填參數:
175
#$conf["fileArgu"],字串,變數__FILE__的內容.
176
$conf["fileArgu"]=__FILE__;
177
#可省略參數:
178
#$conf["listenIp"],字串,要接聽的主機ip,預設為本機的ip.
179
#$conf["listenIp"]="192.168.200.111";
180
#$conf["listenPort"],字串,要接聽的port,預設為已使用port+1.
181
$conf["listenPort"]="9999";
182
#參考資料:
183
#http://php.net/manual/en/sockets.examples.php
184
#備註:
185
#僅能在命令列執行
186
#建構中...
187
$nativeSocketTcpipServer=webSock::nativeSocketTcpipServer($conf);
188
unset($conf);
189
 
190
#如果建立 socket 服務失敗
191
if($nativeSocketTcpipServer["status"]==="false"){
192
 
193
	#印出內容
194
	var_dump($nativeSocketTcpipServer);
195
 
196
	#結束程式
197
	exit;
198
 
199
	}#if end
200
 
201
#印出結果
202
echo $nativeSocketTcpipServer["status"];
203
 
204
*/	
205
 
206
/*
207
 
208
#提示目前要測試的套件
209
echo "<hr>webSock::nativeSocketTcpipServer - testCase 2<br>";	
210
 
211
 
212
#函式說明:
213
#建立php原生的socket
214
#回傳結果:
215
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
216
#$result["error"],錯誤訊息陣列.
217
#$resutl["function"],當前執行的涵式名稱.
218
#$result["argu"],所使用的參數.
219
#必填參數:
220
#無
221
#可省略參數:
222
#$conf["listenIp"],字串,要接聽的主機ip,預設為本機的ip.
223
#$conf["listenIp"]="192.168.1.105";
224
#$conf["listenPort"],字串,要接聽的port,預設為已使用port+1.
225
#$conf["listenPort"]="4000";
226
#參考資料:
227
#http://php.net/manual/en/sockets.examples.php
228
#備註:
229
#僅能在命令列執行
230
#建構中...
231
$nativeSocketTcpipServer=webSock::nativeSocketTcpipServer();
232
unset($conf);
233
 
234
#如果建立 socket 服務失敗
235
if($nativeSocketTcpipServer["status"]==="false"){
236
 
237
	#印出內容
238
	var_dump($nativeSocketTcpipServer);
239
 
240
	#結束程式
241
	exit;
242
 
243
	}#if end
244
 
245
#印出結果
246
echo $nativeSocketTcpipServer["status"];
247
 
248
*/
249
 
250
/*
251
 
252
#提示目前要測試的套件
253
echo "<hr>webSock::nativeSocketTcpipServer - testCase 3<br>";	
254
 
255
#函式說明:
256
#建立php原生的socket
257
#回傳結果:
258
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
259
#$result["error"],錯誤訊息陣列.
260
#$resutl["function"],當前執行的涵式名稱.
261
#$result["argu"],所使用的參數.
262
#必填參數:
263
#無
264
#可省略參數:
265
#$conf["listenIp"],字串,要接聽的主機ip,預設為本機的ip.
266
$conf["listenIp"]="192.168.1.105";
267
#$conf["listenPort"],字串,要接聽的port,預設為已使用port+1.
268
#$conf["listenPort"]="4000";
269
#參考資料:
270
#http://php.net/manual/en/sockets.examples.php
271
#備註:
272
#僅能在命令列執行
273
#建構中...
274
$nativeSocketTcpipServer=webSock::nativeSocketTcpipServer($conf);
275
unset($conf);
276
 
277
#如果建立 socket 服務失敗
278
if($nativeSocketTcpipServer["status"]==="false"){
279
 
280
	#印出內容
281
	var_dump($nativeSocketTcpipServer);
282
 
283
	#結束程式
284
	exit;
285
 
286
	}#if end
287
 
288
#印出結果
289
echo $nativeSocketTcpipServer["status"];
290
 
291
*/
292
 
293
/*
294
 
295
#提示目前要測試的套件
296
echo "<hr>webSock::nativeSocketTcpipServer - testCase 4<br>";	
297
 
298
#函式說明:
299
#建立php原生的socket
300
#回傳結果:
301
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
302
#$result["error"],錯誤訊息陣列.
303
#$resutl["function"],當前執行的涵式名稱.
304
#$result["argu"],所使用的參數.
305
#必填參數:
306
#$conf["fileArgu"],字串,變數__FILE__的內容.
307
$conf["fileArgu"]=__FILE__;
308
#可省略參數:
309
#$conf["listenIp"],字串,要接聽的主機ip,預設為本機的ip.
310
#$conf["listenIp"]="127.0.0.1";
311
#$conf["listenPort"],字串,要接聽的port,預設為已使用port+1.
312
$conf["listenPort"]="4000";
313
#$conf["httpMode"],字串,是否要用http模式,預設為"false",不使用,若為"true"則要使用.
314
$conf["httpMode"]="true";
315
#參考資料:
316
#http://php.net/manual/en/sockets.examples.php
317
#備註:
318
#僅能在命令列執行
319
#建構中...
320
$nativeSocketTcpipServer=webSock::nativeSocketTcpipServer($conf);
321
unset($conf);
322
 
323
#如果建立 socket 服務失敗
324
if($nativeSocketTcpipServer["status"]==="false"){
325
 
326
	#印出內容
327
	var_dump($nativeSocketTcpipServer);
328
 
329
	#結束程式
330
	exit;
331
 
332
	}#if end
333
 
334
#印出結果
335
echo $nativeSocketTcpipServer["status"];
336
 
337
*/
338
 
339
/*
340
 
341
#提示目前要測試的套件
342
echo "<hr>webSock::nativeSocketTcpipServer - testCase 5<br>";	
343
 
344
#函式說明:
345
#建立php原生的socket
346
#回傳結果:
347
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
348
#$result["error"],錯誤訊息陣列.
349
#$resutl["function"],當前執行的涵式名稱.
350
#$result["argu"],所使用的參數.
351
#必填參數:
352
#$conf["fileArgu"],字串,變數__FILE__的內容.
353
$conf["fileArgu"]=__FILE__;
354
#可省略參數:
355
#$conf["listenIp"],字串,要接聽的主機ip,預設為本機的ip.
356
#$conf["listenIp"]="127.0.0.1";
357
#$conf["listenPort"],字串,要接聽的port,預設為已使用port+1.
358
$conf["listenPort"]="4000";
359
#$conf["httpMode"],字串,是否要用http模式,預設為"false",不使用,若為"true"則要使用.
360
#$conf["httpMode"]="true";
361
#參考資料:
362
#http://php.net/manual/en/sockets.examples.php
363
#備註:
364
#僅能在命令列執行
365
#建構中...
366
$nativeSocketTcpipServer=webSock::nativeSocketTcpipServer($conf);
367
unset($conf);
368
 
369
#如果建立 socket 服務失敗
370
if($nativeSocketTcpipServer["status"]==="false"){
371
 
372
	#印出內容
373
	var_dump($nativeSocketTcpipServer);
374
 
375
	#結束程式
376
	exit;
377
 
378
	}#if end
379
 
380
#印出結果
381
echo $nativeSocketTcpipServer["status"];
382
 
383
*/
384
 
385
#/*
386
 
387
#提示目前要測試的套件
388
echo "<hr>webSock::nativeSocketTcpipServer - testCase 6<br>";	
389
echo PHP_EOL;
390
 
391
#函式說明:
392
#建立php原生的socket
393
#回傳結果:
394
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
395
#$result["error"],錯誤訊息陣列.
396
#$resutl["function"],當前執行的涵式名稱.
397
#$result["argu"],所使用的參數.
398
#必填參數:
399
#$conf["fileArgu"],字串,變數__FILE__的內容.
400
$conf["fileArgu"]=__FILE__;
401
#可省略參數:
402
#$conf["listenIp"],字串,要接聽的主機ip,預設為本機的ip.
403
#$conf["listenIp"]="127.0.0.1";
404
#$conf["listenPort"],字串,要接聽的port,預設為已使用port+1.
405
$conf["listenPort"]="4000";
406
#$conf["httpMode"],字串,是否要用http模式,預設為"false",不使用,若為"true"則要使用.
407
$conf["httpMode"]="true";
408
#參考資料:
409
#http://php.net/manual/en/sockets.examples.php
410
#備註:
411
#僅能在命令列執行
412
#建構中...
413
$nativeSocketTcpipServer=webSock::nativeSocketTcpipServer($conf);
414
unset($conf);
415
 
416
#如果建立 socket 服務失敗
417
if($nativeSocketTcpipServer["status"]==="false"){
418
 
419
	#印出內容
420
	var_dump($nativeSocketTcpipServer);
421
 
422
	#結束程式
423
	exit;
424
 
425
	}#if end
426
 
427
#印出結果
428
echo $nativeSocketTcpipServer["status"];
429
 
430
#*/
431
 
432
/*
433
 
434
#提示目前要測試的套件
435
echo "<hr>webSock::connectNativeSocket - testCase 1<br>";
436
 
437
#函數說明:
438
#連線到函數createNativeSocket建立的socket.
439
#回傳結果:
440
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
441
#$result["error"],錯誤訊息陣列.
442
#$resutl["function"],當前執行的涵式名稱.
443
#$result["content"],取得的回應.y
444
#$result["argu"],所使用的參數.
445
#必填參數:
446
#無.
447
#可省略參數:
448
#$conf["targetServr"],字串,要連線的目標,預設為"localhost".
449
#$conf["targetServr"]="";
450
#$conf["targetPort"],字串,要連線的目標port,預設為"80"port.
451
#$conf["targetPort"]="";
452
#備註:
453
#建構中...
454
$connectNativeSocket=webSock::connectNativeSocket();
455
 
456
#如果建立socket連線失敗
457
if($connectNativeSocket["status"]==="false"){
458
 
459
	#印出內容
460
	var_dump($connectNativeSocket);
461
 
462
	#結束程式
463
	exit;
464
 
465
	}#if end
466
 
467
#印出取得的回應
468
echo $connectNativeSocket["content"];
469
 
470
*/
471
 
472
/*
473
 
474
#提示目前要測試的套件
475
echo "<hr>webSock::connectNativeSocket - testCase 2<br>";
476
 
477
#函數說明:
478
#連線到函數createNativeSocket建立的socket.
479
#回傳結果:
480
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
481
#$result["error"],錯誤訊息陣列.
482
#$resutl["function"],當前執行的涵式名稱.
483
#$result["content"],取得的回應.y
484
#$result["argu"],所使用的參數.
485
#必填參數:
486
#無.
487
#可省略參數:
488
#$conf["targetServr"],字串,要連線的目標,預設為"localhost".
489
#$conf["targetServr"]="";
490
#$conf["targetPort"],字串,要連線的目標port,預設為"80"port.
491
$conf["targetPort"]="4000";
492
#備註:
493
#建構中...
494
$connectNativeSocket=webSock::connectNativeSocket($conf);
495
 
496
#如果建立socket連線失敗
497
if($connectNativeSocket["status"]==="false"){
498
 
499
	#印出內容
500
	var_dump($connectNativeSocket);
501
 
502
	#結束程式
503
	exit;
504
 
505
	}#if end
506
 
507
#印出取得的回應
508
echo $connectNativeSocket["content"];
509
 
510
*/
511
 
512
/*
513
 
514
#提示目前要測試的套件
515
echo "<hr>webSock::client - testCase 1<br>";
516
 
517
#函式說明:
518
#webSocket的用戶端
519
#回傳結果:
520
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
521
#$result["error"],錯誤訊息陣列.
522
#$resutl["function"],當前執行的涵式名稱.
523
#$result["argu"],所使用的參數.
524
#必填參數:
525
#$conf["url"],字串要拜訪的web socket,請省略"ws://".
526
$conf["url"]="127.0.0.1:8080";
527
#可省略參數:
528
#$conf["entry"],字串,是否要用加密的wss,預設為"false",代表用ws,若為"true"則為ws.
529
#$conf["entry"]="false";
530
#$conf["connVar"],字串,用來儲存webSocket連線的物件名稱,預設為"conn".
531
#$conf["connVar"]="conn";
532
#備註:
533
#建構中...
534
$client=webSock::client($conf);
535
unset($conf);
536
 
537
#如果建立web socket client 失敗
538
if($client["status"]==="false"){
539
 
540
	#印出錯誤訊息
541
	var_dump(client);
542
 
543
	#結束程式
544
	exit;
545
 
546
	}#if end	
547
 
548
#印出內容
549
echo $client["content"];
550
 
551
*/	
552
 
553
/*
554
 
555
#提示目前要測試的套件
556
echo "<hr>webSock::soldierDemo - testCase 1<br>";
557
 
558
#設置資料庫連線密碼
559
soldier::$dbPassword=$dbPassword;
560
soldier::$dbName="qbpwcf";
561
 
562
#函數說明:
563
#擴充過的Ratchet的聊天室soilier用戶端與伺服端範例,port為8080.
564
#回傳結果:
565
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
566
#$reuslt["error"],執行不正常結束的錯訊息陣列.
567
#$result["function"],當前執行的函式名稱.		
568
#必填參數:
569
#$conf["fileArgu"],字串,__FILE__的內容.
570
$conf["fileArgu"]=__FILE__;
571
#可省略參數:
572
#$conf["disReg"],字串,是否要取消apache的passProxy檢查與設定,預設為"false"不取消,"true"為取消.
573
$conf["disReg"]="true";
574
#參考資料:
575
#Ratchet官網=>http://socketo.me/
576
#聊天室範例=>http://socketo.me/docs/hello-world
577
#備註:
578
#必須要在命令列環境下執行一次,建立webSocket Server後,再於網頁端執行即可產生webSocket Client端的code.
579
#僅適用於https網頁透過wss連線到web socket server.
580
$soldierDemo=webSock::soldierDemo($conf);
581
 
582
#如果執行失敗
583
if($soldierDemo["status"]==="false"){
584
 
585
	#印出結果
586
	var_dump($soldierDemo);
587
 
588
	#結束程式
589
	exit;
590
 
591
	}#if end
592
 
593
#如果存在 $soldierDemo["content"] 則查看結果
594
if(isset($soldierDemo["content"])){
595
 
596
	#印出語法
597
	echo $soldierDemo["content"];
598
 
599
	}#if end
600
 
601
*/
602
 
603
/*
604
 
605
#提示目前要測試的套件
606
echo "<hr>webSock::soldierDemo - testCase 1<br>";
607
 
608
#設置資料庫連線密碼
609
ChatV3::$dbPassword=$dbPassword;
610
 
611
#函數說明:
612
#擴充過的Ratchet的聊天室用戶端與伺服端範例第三版,port為8080.
613
#回傳結果:
614
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
615
#$reuslt["error"],執行不正常結束的錯訊息陣列.
616
#$result["function"],當前執行的函式名稱.		
617
#必填參數:
618
#$conf["fileArgu"],字串,__FILE__的內容.
619
$conf["fileArgu"]=__FILE__;
620
#可省略參數:
621
#$conf["disReg"],字串,是否要取消apache的passProxy檢查與設定,預設為"false"不取消,"true"為取消.
622
$conf["disReg"]="true";
623
#參考資料:
624
#Ratchet官網=>http://socketo.me/
625
#聊天室範例=>http://socketo.me/docs/hello-world
626
#備註:
627
#必須要在命令列環境下執行一次,建立webSocket Server後,再於網頁端執行即可產生webSocket Client端的code.
628
#僅適用於https網頁透過wss連線到web socket server.
629
$chatRoomDemoV3=webSock::chatRoomDemoV3($conf);
630
 
631
#如果建立chat room v3失敗
632
if($chatRoomDemoV3["status"]==="false"){
633
 
634
	#印出內容
635
	var_dump($chatRoomDemoV3);	
636
 
637
	#結束程式
638
	exit;
639
 
640
	}#if end
641
 
642
#如果存在 $chatRoomDemoV3["content"] 則查看結果
643
if(isset($chatRoomDemoV3["content"])){
644
 
645
	#印出語法
646
	echo $chatRoomDemoV3["content"];
647
 
648
	}#if end
649
 
650
*/
651
 
652
/*
653
 
654
#提示目前要測試的套件
655
echo "<hr>webSock::soldierServerDemo - testCase 1<br>";
656
 
657
#設置資料庫名稱	
658
soldier::$dbName="qbpwcf";	
659
 
660
#設置資料庫連線密碼
661
soldier::$dbPassword=$dbPassword;
662
 
663
#函數說明:
664
#擴充過的Ratchet聊天室伺服端soldier範例,port為8080.
665
#回傳結果:
666
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
667
#$reuslt["error"],執行不正常結束的錯訊息陣列.
668
#$result["function"],當前執行的函式名稱.		
669
#必填參數:
670
#$conf["fileArgu"],__FILE__的內容.
671
$conf["fileArgu"]=__FILE__;
672
#可省略參數:
673
#$conf["port"],要 listen 的 port
674
$conf["port"]=8888;
675
#參考資料:
676
#Ratchet官網=>http://socketo.me/
677
#聊天室範例=>http://socketo.me/docs/hello-world
678
#備註:
679
#必須要在命令列環境下執行才行.
680
webSock::soldierServerDemo($conf);
681
unset($conf);
682
 
683
*/
684
 
685
?>