-
Notifications
You must be signed in to change notification settings - Fork 83
/
main.php
125 lines (104 loc) · 3.39 KB
/
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?
function init(){
print("php init...\n");
}
function cleanup(){
print("php cleanup...\n");
}
// we set a larger memory limit just in case
ini_set('memory_limit', '1000M');
function onSessionReq($sessionid, $cmd, $body){
print('onSessionReq:'.$sessionid.','.$cmd.','.$body."\n");
$ip = h2ext::getSessionIp($sessionid);
h2ext::sessionSendMsg($sessionid, $cmd, '服务器收到消息,sessionid:'.$sessionid.',ip:'.$ip.',cmd:'.$cmd.',data:'. $body);
return;
}
function onSessionOffline($sessionid){
print('onSessionOffline:'.$sessionid."\n");
}
function timer_cb_p(){
print("timer_cb_p:\n");
print("timer_cb_p: end***************************\n");
}
function timer_cb(){
h2ext::regTimer(1, "timer_cb");
}
for ($x=0; $x<=1000; $x++) {
//h2ext::regTimer(1, timer_cb);
}
h2ext::regTimer(1000, timer_cb_p);
h2ext::regTimer(2000, timer_cb_p);
h2ext::regTimer(3000, timer_cb_p);
print ("main.php.........\n");
$dbid = h2ext::connectDB("sqlite://./test.db", 'TestGroup');
$sql = 'select * from foo';
function db_cb($retdata){
//var_dump($retdata);
h2ext::asyncQuery($dbid, $sql, db_cb);
}
//h2ext::asyncQuery($dbid, $sql, db_cb);
for ($x=0; $x<=1000000; $x++) {
//h2ext::query($dbid, $sql);
}
function onWorkerCall($cmd, $data){
//print('onWorkerCall'.$cmd.":".$data);
return "rpcok!!";
}
$url = "https://git.oschina.net/ownit/spython/raw/master/ma.py";
function http_cb($rpcret){
//print('rpcret:'.$rpcret);
h2ext::asyncHttp($url, 1, http_cb);
}
//h2ext::asyncHttp($url, 1, http_cb);
function rpc_cb($rpcret){
print('rpcret:'.$rpcret);
//
// h2ext::workerRPC(0, 101, 'OhNice', rpc_cb);
}
h2ext::workerRPC(0, 101, 'OhNice', rpc_cb);
// for($i = 0; $i < 10000*1000; $i++)
// $ret = h2ext::callFunc("Server.foo", 12345678901234567, 'ssss', 22.33, array('cc' => 'b'), array(1,2,3));
// var_dump($ret);
function testScriptCall($arg1 = 0, $arg2 = 0, $arg3 = 0, $arg4 = 0, $arg5 = 0, $arg6 = 0, $arg7 = 0, $arg8 = 0, $arg9 = 0){
print('testScriptCall'.":".$arg1.":".$arg2.":".$arg3.":".$arg4.":".$arg5.":".$arg6.":".$arg7.":".$arg8.":".$arg9."\n");
return 1122334;
}
function testScriptCache(){
print("xxx\n");
h2ext::callFunc("Cache.set", "m.n[10]", "mmm1");
$cacheRet = h2ext::callFunc("Cache.get", "m.n[0]");
print("cacheRet".$cacheRet);
$cacheRet = h2ext::callFunc("Cache.get", "");
//var_dump($cacheRet);
print("cacheRet:".h2ext::callFunc("Cache.size", "m").":".h2ext::callFunc("Cache.size", "m.n")."\n");
}
testScriptCache();
function dbTestCb($ret){
var_dump('dbTest asyncQuery');
//var_dump(ret)
}
function dbTest(){
$sql = 'create table IF NOT EXISTS foo (num integer);';
h2ext::query($sql);
$sql = "insert into foo (num) values ('100');";
$ret = h2ext::query($sql);
var_dump('dbTest');
$ret = h2ext::query('select * from foo limit 1') ;
//h2ext::print('dbTest', ret);
h2ext::asyncQuery(0, 'select * from foo limit 1', 'dbTestCb');
$dbname = 'myDB';
h2ext::connectDB("sqlite://./test.db", $dbname);
$ret = h2ext::queryByName($dbname, 'select * from foo limit 1');
//h2ext::print('dbTest queryByName')
//var_dump(ret)
h2ext::asyncQueryByName(dbname, 'select * from foo limit 2', 'dbTestCb');
}
dbTest();
class FooClass
{
public static function sayhi($arg = 'nothing'){
print("hi !".$arg."\n");
return 0;
}
};
?>