Subversion Repositories php-qbpwcf

Rev

Rev 122 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/usr/bin/php
<?php

/*
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
    Copyright (C) 2015~2024 Min-Jhin,Chen

    This file is part of QBPWCF.

    QBPWCF is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QBPWCF is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
    
*/

/*

說明:
提供QBPWCF套件執行任何指令的unix domain socket服務.

*/

#使用命名空間qbpwcf
namespace qbpwcf;

#取得 lib path
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/libexec/folderOfUsrLib.php"),$output,$status);

#如果執行失敗
if($status!==0){

        #debug
        var_dump(__LINE__,$output);

        #結束執行,回傳shell 1.
        exit(1);

        }#if end

#儲存lib path
$folderOfUsrLib=$output[0];

#以該檔案的實際位置的 lib path 為 include path 首位
$output=array();
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);

#如果執行失敗
if($status!==0){

        #debug
        var_dump(__LINE__,$output);

        #結束執行,回傳shell 1.
        exit(1);

        }#if end

#設置 include path 
set_include_path($output[0].PATH_SEPARATOR.get_include_path());

#匯入外部套件
include("allInOne.php");

#函式說明:
#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用.
#回傳結果:
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
#$result["error"],錯誤訊息陣列.
#$result["function"],當前執行的函式名稱.
#必填參數:
#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.
$conf["sock"]=qbpwcf_usock_path;
#$conf["fileArgu"],字串,變數__FILE__的內容.
$conf["fileArgu"]=__FILE__;
#可省略參數:
#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.
$conf["changeOwner"]="root.apache";
#$conf["changePermission"],整數,要將socket檔案的權限設為多少.ex: 0666(所有帳戶都有存取的權限) 或 0660(僅有擁有者與群組帳戶有存取的權限) 或 0600(只有擁有者有權限執行).
$conf["changePermission"]="0770";
#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.
#$conf["sessionTimeout"]="300";
#參考資料:
#http://php.net/manual/en/function.stream-socket-server.php
#備註:
#無.
$unixDomainSockServer=sock::unixDomainSockServer($conf);
unset($conf);

#如果執行失敗
if($unixDomainSockServer["status"]=="false"){
        
        #設置錯誤識別
        $result["status"]="false";
        
        #設置錯誤訊息
        $result["error"]=$unixDomainSockServer;
        
        #印出結果
        var_dump($result);
        
        #結束執行
        exit;
        
        }#if end