<?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); ?>