forked from whcyc2002/swoole_framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstruct.php
More file actions
72 lines (61 loc) · 1.14 KB
/
Copy pathstruct.php
File metadata and controls
72 lines (61 loc) · 1.14 KB
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
<?php
define('DEBUG', 'on');
define('WEBPATH', realpath(__DIR__ . '/..'));
//包含框架入口文件
require WEBPATH . '/libs/lib_config.php';
class BStruct extends Swoole\Memory\Struct
{
/**
* @fieldtype char[64]
*/
public $key;
/**
* @fieldType int16
*/
public $num;
}
class AStruct extends Swoole\Memory\Struct
{
/**
* @fieldtype int32
*/
public $id;
/**
* @fieldtype char[40]
*/
public $data;
/**
* @fieldtype double
*/
public $price;
/**
* @fieldtype float
*/
public $price2;
/**
* @fieldtype struct[BStruct]
*/
public $b;
/**
* @fieldtype int64
*/
public $count;
}
$a = new AStruct(false, true);
$n = 1;
$s = microtime(true);
for ($i = 0; $i < $n; $i++)
{
$str = $a->pack(array(
'id' => 13,
'data' => 'hello world',
'price' => 999.9,
'price2' => 888.8,
'b' => array('key' => 'redis', 'num' => 5566,),
'count' => 99999,
));
}
echo "$n pack, cost time ".(microtime(true) - $s)."s\n";
var_dump(strlen($str));
$result = $a->unpack($str);
var_dump($result);