-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathkvstorage-shmop.inc
More file actions
48 lines (44 loc) · 1.05 KB
/
kvstorage-shmop.inc
File metadata and controls
48 lines (44 loc) · 1.05 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
<?php
/**
* Php 5.2+
*/
class KVStorageShmop
{
public $available = false;
public function __construct(){
$this->available=true;
if (!function_exists('shmop_open'))
$this->available=false;
if (!function_exists('shmop_write'))
$this->available=false;
if (!function_exists('shmop_read'))
$this->available=false;
if (!function_exists('shmop_size'))
$this->available=false;
if (!function_exists('shmop_close'))
$this->available=false;
}
public function set($key, $value, $timeout=60){
$id=shmop_open(1, "a", 0, 0);
if ($id===false) return false;
$ret=shmop_write($id, $value, 0);
shmop_close($id);
return $ret;
}
public function get($key, $default=null){
$id=shmop_open(1, "a", 0, 0);
if ($id===false) return false;
$size=shmop_size($id);
$ret=shmop_read($id,0,$size);
shmop_close($id);
return $ret;
}
public function del($key){
$id=shmop_open(1, "a", 0, 0);
if ($id===false) return false;
$ret=shmop_delete($id);
shmop_close($id);
return $ret;
}
}
$kvstorage=new KVStorageShmop();