1 | <?php |
||
8 | class SharedMemory |
||
9 | { |
||
10 | use IpcKeyTrait; |
||
11 | |||
12 | /** |
||
13 | * The resource that be generated after call "shm_attach" |
||
14 | * @var resource |
||
15 | */ |
||
16 | protected $shmId; |
||
17 | |||
18 | /** |
||
19 | * The size of the shared memory |
||
20 | * @var int |
||
21 | */ |
||
22 | protected $size; |
||
23 | |||
24 | public function __construct($pathname = __FILE__, $size = null, $permission = 0666) |
||
34 | |||
35 | /** |
||
36 | * Gets a value from the shared memory |
||
37 | * @param $key |
||
38 | * @return mixed |
||
39 | */ |
||
40 | public function get($key) |
||
44 | |||
45 | /** |
||
46 | * Persists data in the shared memory |
||
47 | * @param string $key |
||
48 | * @param mixed $value |
||
49 | * @return bool |
||
50 | */ |
||
51 | public function set($key, $value) |
||
55 | |||
56 | /** |
||
57 | * Delete an item from the shared memory by its key |
||
58 | * @param string $key |
||
59 | * @return bool |
||
60 | */ |
||
61 | public function delete($key) |
||
65 | |||
66 | /** |
||
67 | * Checks whether an item exists in the shared memory |
||
68 | * @param string $key |
||
69 | * @return bool |
||
70 | */ |
||
71 | public function has($key) |
||
75 | |||
76 | /** |
||
77 | * Deletes all items |
||
78 | */ |
||
79 | public function clear() |
||
83 | |||
84 | /** |
||
85 | * Checks whether the memory is enabled |
||
86 | * @return bool |
||
87 | */ |
||
88 | public function isEnabled() |
||
92 | |||
93 | /** |
||
94 | * Disconnects from shared memory |
||
95 | */ |
||
96 | public function close() |
||
100 | |||
101 | |||
102 | /** |
||
103 | * Removes all items and disconnects from shared memory |
||
104 | * @return void |
||
105 | */ |
||
106 | public function destroy() |
||
113 | |||
114 | /** |
||
115 | * Generate the variable key |
||
116 | * @param string $val |
||
117 | * @return string int |
||
118 | */ |
||
119 | protected function generateShmKey($val) |
||
124 | |||
125 | /** |
||
126 | * Convert human readable file size (e.g. "10K" or "3M") into bytes |
||
127 | * @link https://github.com/brandonsavage/Upload/blob/master/src/Upload/File.php#L446 |
||
128 | * @param string $input |
||
129 | * @return int |
||
130 | */ |
||
131 | public static function humanReadableToBytes($input) |
||
146 | } |
||
147 |