-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
48 lines (36 loc) · 1.25 KB
/
test.php
File metadata and controls
48 lines (36 loc) · 1.25 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
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
require __DIR__ . '/vendor/autoload.php';
use LinkORB\Component\Etcd\Client;
$cache_path = '/tmp/confcache';
function cache_set($key, $val) {
global $cache_path;
echo "set key: $key";
$val = var_export($val, true);
// HHVM fails at __set_state, so just use object cast for now
$val = str_replace('stdClass::__set_state', '(object)', $val);
// Write to temp file first to ensure atomicity
$tmp = $cache_path.$key."." . uniqid('', true) . '.tmp';
file_put_contents($tmp, '<?php $val = ' . $val . ';', LOCK_EX);
rename($tmp, "$cache_pathe$key");
}
function get_key($key) {
global $cache_path;
if(!substr($key, 0, 1) === "/") {
throw new Exception('key must start with /');
}
@include "$cache_path$key";
if(isset($val)) {
return $val;
}
$client = new Client('http://127.0.0.1:2379', 'username', 'password');
$val = $client->get($key);
cache_set($key, $val);
return $val;
}
$client = new Client('http://127.0.0.1:2379', 'username', 'password');
// $client->set('/foo', 'fooValue');
// Set the ttl
// $client->set('/foo', 'fooValue', 10);
echo get_key('/foo');