Blame | Last modification | View Log | RSS feed
<?php#宣告指派命名空間namespace qbpwcf;#匯入外部套件include("../allInOne.php");/*#提示目前要測試的涵式echo"<hr>sock::unixDomainSockServer - testCase 1<p>";#函式說明:#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用.#回傳結果:#$result["status"],"true"代表執行正常;"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.$conf["sock"]="sock_unixDomainSockServer_testCase1";#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.#$conf["changeOwner"]="";#$conf["changePermission"],整數,要將socket檔案的權限設為多少.ex: 666(所有帳戶都有存取的權限) 或 660(僅有擁有者與群組帳戶有存取的權限) 或 600(只有擁有者有權限執行).#$conf["changePermission"]="";#參考資料:#http://php.net/manual/en/function.stream-socket-server.php$unixDomainSockServer=sock::unixDomainSockServer($conf);unset($conf);#如果建立 unix domain socket 失敗if($unixDomainSockServer["status"]==="false"){#印出內容var_dump($unixDomainSockServer);#結束執行exit;}#if end#印出內容var_dump($unixDomainSockServer);*//*#提示目前要測試的涵式echo"<hr>sock::tcpServer - testCase 1".PHP_EOL;#函式說明:#建立tcp server#必填參數:#$conf["port"],整數,tcp server listen port.$conf["port"]=7053;#可省略參數:#$conf["ip"],整數字串,tcp serer listen ip, default is 0.0.0.0.#$conf["ip"]="0.0.0.0";#$conf["processFuncs"],字串陣列,要將收到的訊息作什麼事情的函式們,預設為空陣列.$conf["processFuncs"]=array("qbpwcf\sock::echoService","qbpwcf\sock::endService");$tcpServer=sock::tcpServer($conf);unset($conf);#如果建立 tcp socket 失敗if($tcpServer["status"]==="false"){#印出內容var_dump($tcpServer);#結束執行exit;}#if end#印出內容var_dump($tcpServer);*//*#提示目前要測試的涵式echo"<hr>sock::tcpServer - testCase 2".PHP_EOL;#函式說明:#建立tcp server#必填參數:#$conf["port"],整數,tcp server listen port.$conf["port"]=7890;#可省略參數:#$conf["ip"],整數字串,tcp serer listen ip, default is 0.0.0.0.#$conf["ip"]="0.0.0.0";#$conf["processFuncs"],字串陣列,要將收到的訊息作什麼事情的函式們,預設為空陣列.#$conf["processFuncs"]=array();#$conf["socketSelectTimeountSec"],整數,代表要等候幾秒才抓取有異動的連線,預設為0代表立即抓取有異動的連線.#$conf["socketSelectTimeountSec"]=0;#$conf["socketSelectTimeountUsec"],整數,代表要等候幾微秒才抓取有異動的連線,預設不使用.$conf["socketSelectTimeountUsec"]=5000;$tcpServer=sock::tcpServer($conf);unset($conf);#如果建立 tcp socket 失敗if($tcpServer["status"]==="false"){#印出內容var_dump($tcpServer);#結束執行exit;}#if end#印出內容var_dump($tcpServer);*//*#提示目前要測試的涵式echo"<hr>sock::udpServer - testCase 1".PHP_EOL;#函式說明:#建立udp server#必填參數:#$conf["port"],整數,udp server listen port.$conf["port"]=7051;#可省略參數:#$conf["ip"],整數字串,udp serer listen ip, default is 0.0.0.0.#$conf["ip"]="0.0.0.0";#$conf["processFuncs"],字串陣列,要將收到的訊息作什麼事情的函式們,預設為空陣列.$conf["processFuncs"]=array("qbpwcf\sock::echoServiceU","qbpwcf\sock::endServiceU");#$conf["welcomeMsg"],字串,是否要顯示歡迎訊息,預設為"true"代表要顯示歡迎訊息;"false"代表不要顯示歡迎訊息.$conf["welcomeMsg"]="false";$udpServer=sock::udpServer($conf);unset($conf);#如果建立 udp socket 失敗if($udpServer["status"]==="false"){#印出內容var_dump($udpServer);#結束執行exit;}#if end#印出內容var_dump($udpServer);*//*#提示目前要測試的涵式echo"<hr>sock::udpServer - testCase 2".PHP_EOL;#函式說明:#建立 udp server#必填參數:#$conf["port"],整數,udp server listen port.$conf["port"]=7051;#可省略參數:#$conf["ip"],整數字串,udp serer listen ip, default is 0.0.0.0.#$conf["ip"]="0.0.0.0";#$conf["processFuncs"],字串陣列,要將收到的訊息作什麼事情的函式們,預設為空陣列.#$conf["processFuncs"]=array();#$conf["welcomeMsg"],字串,是否要顯示歡迎訊息,預設為"true"代表要顯示歡迎訊息;"false"代表不要顯示歡迎訊息.#$conf["welcomeMsg"]="true";#$conf["socketSelectTimeountSec"],整數,代表要等候幾秒才抓取有異動的連線,預設為0代表立即抓取有異動的連線,但是會吃很多cpu.#$conf["socketSelectTimeountSec"]=1;#$conf["socketSelectTimeountUsec"],整數,代表要等候幾微秒才抓取有異動的連線,預設不使用.$conf["socketSelectTimeountUsec"]=5000;#參考資料:#https://www.jianshu.com/p/097463d08664$udpServer=sock::udpServer($conf);unset($conf);#如果建立 udp socket 失敗if($udpServer["status"]==="false"){#印出內容var_dump($udpServer);#結束執行exit;}#if end#印出內容var_dump($udpServer);*//*#提示目前要測試的涵式echo"<hr>sock::udpClient - testCase 1".PHP_EOL;#函式說明:#udp client#回傳結果:#$result["status"],"true"代表執行正常;"false"代表執行不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],使用的參數.#$result["content"],取得的回應內容字串,為每個回應的內容直接串接.#$result["contentArray"],取得的回應字串陣列,為每個回應的內容,各別儲存成陣列中的元素.#$result["sock"],可重複使用的socket資源.#必填參數:#$conf["port"],整數,target port.$conf["port"]=7053;#$conf["dataToSend"],陣列字串,要傳送的多個訊息,每個訊息傳送結束後才會讀取回應.$conf["dataToSend"]=array("123456");#可省略參數:#$conf["ip"],整數字串,tcp serer listen ip, default is 127.0.0.1.$conf["ip"]="aesopower-cms-demo.qbpwcf.org";#$conf["timeout"],整數,預設為10秒,代表接收訊息的等待時間上限.#$conf["timeout"]=10;#$conf["secSleepAfterSend"],整數,預設為1秒.#$conf["secSleepAfterSend"]=1;#$conf["closeAtEnd"],字串,預設為"true",代表函式結束後要斷開連線.#$conf["closeAtEnd"]="true";#$conf["sock"],resource,要重複使用的socket資源,預設不指定.#$conf["sock"]=;#參考資料:#https://www.php.net/manual/en/sockets.examples.php$udpClient=sock::udpClient($conf);unset($conf);var_dump($udpClient);var_dump(gettype($udpClient["sock"]));*/?>