1: | <?php |
2: | |
3: | namespace ngatngay\session\storage; |
4: | |
5: | use SessionHandlerInterface; |
6: | use ReturnTypeWillChange; |
7: | |
8: | class apcu implements SessionHandlerInterface |
9: | { |
10: | private string $prefix; |
11: | private int $ttl; |
12: | |
13: | public function __construct(string $prefix = 'sess_', int $ttl = 86400) |
14: | { |
15: | $this->prefix = $prefix; |
16: | $this->ttl = $ttl; |
17: | } |
18: | |
19: | #[ReturnTypeWillChange] |
20: | public function close() |
21: | { |
22: | return true; |
23: | } |
24: | |
25: | #[ReturnTypeWillChange] |
26: | public function destroy($id) |
27: | { |
28: | $key = $this->prefix . $id; |
29: | return apcu_delete($key); |
30: | } |
31: | |
32: | #[ReturnTypeWillChange] |
33: | public function gc($max_lifetime) |
34: | { |
35: | return 1; |
36: | } |
37: | |
38: | #[ReturnTypeWillChange] |
39: | public function open($path, $name) |
40: | { |
41: | return true; |
42: | } |
43: | |
44: | #[ReturnTypeWillChange] |
45: | public function read($id) |
46: | { |
47: | $key = $this->prefix . $id; |
48: | return apcu_exists($key) ? apcu_fetch($key) : ''; |
49: | } |
50: | |
51: | #[ReturnTypeWillChange] |
52: | public function write($id, $data) |
53: | { |
54: | $key = $this->prefix . $id; |
55: | return apcu_store($key, $data, $this->ttl); |
56: | } |
57: | } |