1 | <?php |
||
11 | class ShmEntity |
||
12 | { |
||
13 | use \PHPDaemon\Traits\ClassWatchdog; |
||
14 | use \PHPDaemon\Traits\StaticObjectWatchdog; |
||
15 | |||
16 | /** |
||
17 | * @var string Path |
||
18 | */ |
||
19 | protected $path; |
||
20 | |||
21 | /** |
||
22 | * @var array Segments |
||
23 | */ |
||
24 | protected $segments = []; |
||
25 | |||
26 | /** |
||
27 | * @var integer Segment size |
||
28 | */ |
||
29 | protected $segsize = 1024; |
||
30 | |||
31 | /** |
||
32 | * @var string Name |
||
33 | */ |
||
34 | protected $name; |
||
35 | |||
36 | /** |
||
37 | * @var integer Key |
||
38 | */ |
||
39 | protected $key; |
||
40 | |||
41 | /** |
||
42 | * Constructor |
||
43 | * @param string $path Path |
||
44 | * @param integer $segsize Segment size |
||
45 | * @param string $name Name |
||
46 | * @param boolean $create Create |
||
47 | */ |
||
48 | public function __construct($path, $segsize, $name, $create = false) |
||
67 | |||
68 | /** |
||
69 | * Opens segment of shared memory |
||
70 | * @param integer $segno Segment number |
||
71 | * @param boolean $create Create |
||
72 | * @return integer Segment number |
||
73 | */ |
||
74 | public function open($segno = 0, $create = false) |
||
98 | |||
99 | /** |
||
100 | * Get open segments |
||
101 | * @return array |
||
102 | */ |
||
103 | public function getSegments() |
||
107 | |||
108 | /** |
||
109 | * Open all segments |
||
110 | * @return void |
||
111 | */ |
||
112 | public function openall() |
||
118 | |||
119 | /** |
||
120 | * Write to shared memory |
||
121 | * @param string $data Data |
||
122 | * @param integer $offset Offset |
||
123 | * @return boolean Success |
||
124 | */ |
||
125 | public function write($data, $offset) |
||
143 | |||
144 | /** |
||
145 | * Read from shared memory |
||
146 | * @param integer $offset Offset |
||
147 | * @param integer $length Length |
||
148 | * @return string Data |
||
149 | */ |
||
150 | public function read($offset, $length = 1) |
||
176 | |||
177 | /** |
||
178 | * Deletes all segments |
||
179 | * @return void |
||
180 | */ |
||
181 | public function delete() |
||
187 | } |
||
188 |