Subversion Repositories php-qbpwcf

Rev

Rev 81 | Rev 224 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2014~2025 Min-Jhin,Chen
7
 
8
    This file is part of QBPWCF.
9
 
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
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
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/>.
22
 
23
*/
24
 
25
#使用命名空間qbpwcf
26
namespace qbpwcf;
27
 
28
#assets dir
29
$assetsDir="assets of sock::unixDomainSockServer_20250228";
30
 
31
#函式說明:
32
#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.
33
#回傳結果:
34
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
35
#$result["error"],錯誤訊息陣列.
36
#$result["function"],當前執行的函式名稱.
37
#$result["serverCache"],函式結束前,儲存在serverCache的內容,若有元素"exit"存在則代表是正常結束.
38
#$result["serverCache"]["serverSide"],server side 的 cache.
39
#$result["serverCache"]["serverSide"]["procs"], server side 的 procs cache,儲存執行的子程序資訊.
40
#$result["serverCache"]["clientSide"],client site 的 cache.
41
#必填參數:
42
#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.
43
$conf["sock"]=$assetsDir."/unixDomainSockServer.sock";
44
#$conf["fileArgu"],字串,變數__FILE__的內容.
45
$conf["fileArgu"]=__FILE__;
46
#可省略參數:
47
#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.
48
#$conf["changeOwner"]="";
49
#$conf["changePermission"],字串,要將socket檔案的權限設為多少.ex: "0666"(所有帳戶都有存取的權限) 或 "0660"(僅有擁有者與群組帳戶有存取的權限) 或 "0600"(只有擁有者有權限執行).
220 liveuser 50
$conf["changePermission"]="770";
6 liveuser 51
#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.
52
#$conf["sessionTimeout"]="300";
53
#$conf["addOnProcessFunc"],字串陣列,增加用於處理 json request 的函式名稱,給予的參數為array("request"=>收到的json訊息,"sock"=>用戶的socket,"clientCache"=>給予所有用戶的cache),若收到的不是json而是"quit"則代表用戶要結束連線;若收到的是$shutdownStr則代表要結束本函式.回傳的內容必須為陣列,例如 $res["continue"]="true"代表要繼續執行下一個addOnProcessFunc;"false"代表代表到此為止. $res["content"]="replaced content";代表要將收到的訊息取代成"replaced content". 最少要有回傳 $res["status"]數值"true"代表執行正常;"false"代表執行不正常.
54
#$conf["addOnProcessFunc"]=array();
55
#$conf["funcToRunWhenIdle"],字串陣列,當沒有事件產生時,要執行的函式名稱,給予參數為array("client"=>所有用戶,"clientCache"=>$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"serverCache"=>$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle]).
56
#$conf["funcToRunWhenIdle"]=array();
57
#$conf["paramsForFuncToRunWhenIdle"],2維陣列,每個元素代表指定給予funcToRunWhenIdle參數中的指定元素的參數.
58
#$conf["paramsForFuncToRunWhenIdle"]=array();
59
#$conf["infoToFunction"],陣列,需要增加給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
60
#$conf["infoToFunction"]=array("debug"=>$debug);
61
#$conf["shutdownStrAddr"],字串,儲存收到用戶傳什麼樣的字串會結束本函式的檔案位置與名稱,預設為 $conf["sock"].".shutdown".
62
#$conf["shutdownStrAddr"]="";
63
#參考資料:
64
#http://php.net/manual/en/function.stream-socket-server.php
65
#備註:
66
#無.
67
$unixDomainSockServer=sock::unixDomainSockServer($conf);
68
unset($conf);
69
 
70
#debug
71
var_dump($unixDomainSockServer);