-
Notifications
You must be signed in to change notification settings - Fork 1
/
IlldbBrowser.class.php
53 lines (48 loc) · 1.43 KB
/
IlldbBrowser.class.php
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
49
50
51
52
53
<?php
class IlldbBrowser{
const BASE_COMMAND='python illdb_browser.py';
private $connectString;
public function connect($profile){
//TODO Add mutil profiles support
require_once 'defines/Illdb.conf.php';
$confKey=strtoupper("ILLDB_" . $profile);
if (!defined("{$confKey}_HOST") ||
!defined("{$confKey}_PORT") ||
!defined("{$confKey}_USER") ||
!defined("{$confKey}_PWD")){
throw new Exception("Unknown illdb server $profile");
}
$this->connectString=sprintf('--host %s --port %s -u %s -p %s ',
constant("{$confKey}_HOST"),
constant("{$confKey}_PORT"),
constant("{$confKey}_USER"),
constant("{$confKey}_PWD")
);
}
public function getByKey($bucket,$key){
$command=self::BASE_COMMAND . " --bucket={$bucket} {$this->connectString} get '$key' ";
return $this->run($command);
}
public function setKeyValue($bucket,$key,$value){
$command= self::BASE_COMMAND . " --bucket={$bucket} {$this->connectString} set '$key' '$value' ";
echo($command);
return $this->run($command);
}
protected function run($command) {
echo $command;
$descriptionspec=array(
0=>['pipe','r'],
1=>['pipe','w'],
2=>['pipe','w']
);
$handle=proc_open($command,$descriptionspec,$pipes);
$response=stream_get_line($pipes[1],1024);
$error=stream_get_line($pipes[2],1024);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($handle);
return array($response,$error);
}
}
?>