data.php
2.27 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
function rglob($pattern, $flags = 0) {
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$files = array_merge($files, rglob($dir.'/'.basename($pattern), $flags));
}
return $files;
}
function disable_ob() {
// Turn off output buffering
ini_set('output_buffering', 'off');
// Turn off PHP output compression
ini_set('zlib.output_compression', false);
// Implicitly flush the buffer(s)
ini_set('implicit_flush', true);
ob_implicit_flush(true);
// Clear, and turn off output buffering
while (ob_get_level() > 0) {
// Get the curent level
$level = ob_get_level();
// End the buffering
ob_end_clean();
// If the current level has not changed, abort
if (ob_get_level() == $level) break;
}
// Disable apache output buffering/compression
if (function_exists('apache_setenv')) {
apache_setenv('no-gzip', '1');
apache_setenv('dont-vary', '1');
}
}
$METADATA_DIR = "/home/budnik/public_html/hapi/PARAM_DEF";
$response = array();
$response["HAPI"] = "2.0";
if (!$_GET["id"]) {
header("HTTP/1.1 404 NO SUCH ID");
$response["status"] = 1406;
$response["msg"] = "NO SUCH ID !!!";
header('Content-Type: application/json');
exit(json_encode($response));
}
header('Content-Type: text/csv');
$id = $_GET["id"];
$tmin = $_GET["time_min"];
$tmax = $_GET["time_max"];
if ($_GET["parameters"]) {
$params = $_GET["parameters"];
}
else {
$params = null;
}
$ddId = strtr($id, "-", "_");
if ($params) {
$cmd = "python -u reader.py -tmin $tmin -tmax $tmax -id $ddId -param $params";
}
else {
$cmd = "python -u reader.py -tmin $tmin -tmax $tmax -id $ddId";
}
disable_ob();
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET");
$handle = popen($cmd, 'r');
while(!feof($handle)) {
$buffer = fgets($handle);
echo "$buffer";
ob_flush();
}
pclose($handle);
?>