-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestGlobalStorage.php
More file actions
55 lines (39 loc) · 1.3 KB
/
testGlobalStorage.php
File metadata and controls
55 lines (39 loc) · 1.3 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
<?php
require("GlobalStorage.php");
class Usage extends \Thread
{
public function __construct()
{
$this->storage = GlobalStorage::getInstance()->alloc('global' . uniqid());
$this->start(PTHREADS_INHERIT_ALL | PTHREADS_ALLOW_GLOBALS);
}
public function run()
{
try {
$tempStorage = GlobalStorage::getInstance()->alloc($tempStorageName = uniqid('tempStorage'));
$tempStorage["asdf"] = 'asdf';
GlobalStorage::getInstance()->free($tempStorageName);
$othersStorage = GlobalStorage::getInstance()->find('ASDFASDF222');
$othersStorage[$this->getThreadId()] = $this->getThreadId() . ' was here';
$this->storage["threadId"] = $this->getThreadId();
} catch (\Exception $e) {
die($e);
}
}
}
GlobalStorage::init();
GlobalStorage::getInstance()->alloc("ASDFASDF111");
GlobalStorage::getInstance()->alloc("ASDFASDF222");
$t = new \Usage();
$u = array();
for ($i = 1; $i <= 10; $i++) {
$u[$i] = new \Usage();
}
for ($i = 1; $i <= 10; $i++) {
$u[$i]->join();
}
GlobalStorage::getInstance()->free("ASDFASDF111");
var_dump(GlobalStorage::getInstance());
// shutdown GlobalStorage
GlobalStorage::getInstance()->shutdown();
var_dump(GlobalStorage::getInstance());