Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
397 liveuser 1
<?php
2
 
3
 
4
/*
5
 
6
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
7
    Copyright (C) 2014~2026 MIN ZHI, CHEN
8
 
9
    This file is part of QBPWCF.
10
 
11
    QBPWCF is free software: you can redistribute it and/or modify
12
    it under the terms of the GNU General Public License as published by
13
    the Free Software Foundation, either version 3 of the License, or
14
    (at your option) any later version.
15
 
16
    QBPWCF is distributed in the hope that it will be useful,
17
    but WITHOUT ANY WARRANTY; without even the implied warranty of
18
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
    GNU General Public License for more details.
20
 
21
    You should have received a copy of the GNU General Public License
22
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
23
 
24
*/
25
 
26
#使用命名空間qbpwcf
27
namespace qbpwcf;
28
 
29
#初始化輸出
30
$output=array();
31
 
32
#取得 lib path
33
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../../../../usr/bin/libexec/folderOfUsrLib.php"),$output,$status);
34
 
35
#如果執行失敗
36
if($status!==0){
37
 
38
	#debug
39
	var_dump(__LINE__,$output);
40
 
41
	#結束執行,回傳shell 1.
42
	exit(1);
43
 
44
	}#if end
45
 
46
#儲存lib path
47
$folderOfUsrLib=$output[0];
48
 
49
#初始化輸出
50
$output=array();
51
 
52
#以該檔案的實際位置的 lib path 為 include path 首位
53
exec("cd ".\escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../../../../usr/".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);
54
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
55
 
56
#匯入套件
57
require_once("allInOne.php");
58
 
59
#建議的log位置
60
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";
61
 
62
/* test run by proc will end.
63
 
64
#迴圈
65
for($i=10;$i>0;$i--){
66
 
67
	#提示訊息
68
	echo $i." 秒後結束".PHP_EOL;
69
 
70
	#休息一秒
71
	sleep(1);
72
 
73
	}#for end
74
 
75
#break point
76
exit;
77
 
78
*/
79
 
80
#函式說明:
81
#存取快取服務.
82
#回傳結果:
83
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
84
#$reuslt["error"],執行不正常結束的錯訊息陣列.
85
#$result["function"],當前執行的函式名稱.
86
#$result["argu"],所使用的參數.
87
#$result["content"],得到的回應字串.
88
#必填參數:
89
#$conf["action"],字串,"read":代表要讀取資料;"write":代表要寫入資料.
90
$conf["action"]="write";
91
#$conf["type"],字串,"php_variable":php的變數;"proc",透過proc運行的程序,可透過標準輸入進行操作.
92
$conf["type"]="php_variable";
93
#可省略參數:
94
#$conf["value"],null,"action"參數為write時,資源的內容,形態不固定.
95
$conf["value"]=time();
96
#$conf["sock"],字串,unix domain socket的路徑與名稱,預設為相對於當前套件的 var/qbpwcf/resource.sock
97
$conf["sock"]="resource.sock";
98
#$conf["condition"],陣列,條件,預設為空陣列,代表沒有條件,通常是為新增資源,元素的key為"id"者代表目標資源的id;元素的key為"value"者代表目標資源是否相等於"value",且"type"為"php_variable";元素的key為"pid"者代表運行的資源程序pid,且"type"為"proc"
99
#$conf["condition"]=array();
100
#參考資料:
101
#無.
102
#備註:
103
#僅能在命令列環境下運行.
104
$client=resource::client($conf);
105
unset($conf);
106
 
107
#debub
108
#var_dump(__LINE__,$client);
109
 
110
#如果執行異常
111
if($client["status"]==="false"){
112
 
113
	#debug
114
	var_dump($client);
115
 
116
	#結束執行,回傳 shell 1.
117
	exit(1);
118
 
119
	}#if end
120
 
121
#印出結果
122
echo $client["content"];
123
 
124
?>