-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathset.php
48 lines (43 loc) · 1.6 KB
/
set.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
<?php
$table = new Swoole\Table(1024);
$table->column('id', Swoole\Table::TYPE_INT, 4); //1,2,4,8
$table->column('name', Swoole\Table::TYPE_STRING, 64);
$table->column('num', Swoole\Table::TYPE_FLOAT);
$table->create();
//$worker = new Swoole\Process('child1', false, false);
//$worker->start();
//
//child
function child1($worker)
{
global $table;
$s = microtime(true);
$table->set('[email protected]', array('id' => 145, 'name' => 'rango', 'num' => 3.1415));
$table->set('[email protected]', array('id' => 358, 'name' => "Rango1234", 'num' => 3.1415));
$table->set('[email protected]', array('id' => 189, 'name' => 'rango3', 'num' => 3.1415));
$table->set('[email protected]', array('id' => 145, 'name' => 'rango', 'num' => 3.1415));
$table->set('[email protected]', array('id' => 358, 'name' => "Rango1234", 'num' => 3.1415));
echo "set - 5 use: ".((microtime(true) - $s) * 1000)."ms\n";
}
//master
sleep(1);
child1(1245);
$s = microtime(true);
for($i =0; $i < 1000; $i++)
{
$arr = $table->get('[email protected]');
}
echo "get -5 use: ".((microtime(true) - $s) * 1000)."ms\n";
$s = microtime(true);
//$table->incr('[email protected]', 'id', 5);
//$table->decr('[email protected]', 'num', 1.1);
$ret1 = $table->get('[email protected]');
$ret2 = $table->get('[email protected]');
$ret3 = $table->get('[email protected]');
$ret4 = $table->get('[email protected]');
$ret5 = $table->get('[email protected]');
echo "get -5 use: ".((microtime(true) - $s) * 1000)."ms\n";
var_dump($ret1, $ret2, $ret3, $ret4, $ret5);
echo "id:".$ret1['id']."\n";
echo "name:".$ret1['name']."\n";
echo "num:".$ret1['num']."\n";