blob: 35d79a3153a38967ab2e532ead07e666f540a769 (
plain) (
blame)
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
|
<?php
class Dnbd3Rpc {
const QUERY_UNREACHABLE = 1;
const QUERY_NOT_200 = 2;
const QUERY_NOT_JSON = 3;
/**
* Query given DNBD3 server for status information.
*
* @param string $server server address
* @param int $port server port
* @param bool $stats include general stats
* @param bool $clients include client list
* @param bool $images include image list
* @param bool $diskSpace include disk space stats
* @return int|array the queried data as an array, or false on error
*/
public static function query($server, $port, $stats, $clients, $images, $diskSpace)
{
// Special case - local server
if ($server === '<self>') {
$server = '127.0.0.1';
}
$url = 'http://' . $server . ':' . $port . '/query?';
if ($stats) {
$url .= 'q=stats&';
}
if ($clients) {
$url .= 'q=clients&';
}
if ($images) {
$url .= 'q=images&';
}
if ($diskSpace) {
$url .= 'q=space&';
}
$str = Download::asString($url, 3, $code);
if ($str === false)
return self::QUERY_UNREACHABLE;
if ($code !== 200)
return self::QUERY_NOT_200;
$ret = json_decode($str, true);
if (!is_array($ret))
return self::QUERY_NOT_JSON;
return $ret;
}
}
|