3 * Experimental version that return chunked http response.
5 * Pulling the values is no longer needed as the one request will output
6 * the updates every second.
8 require_once('config.php');
9 require_once("ampy.inc.php");
11 $speed=@(int)$_GET['speed'];
16 header("Content-Type: text/json");
17 header("Transfer-Encoding: chunked");
21 // Send chunk to browser
22 function send_chunk($chunk)
24 // The chunk must fill the output buffer or php won't send it
25 //$chunk = str_pad($chunk, 4096);
27 printf("%x\r\n%s\r\n", strlen($chunk), $chunk);
33 ampy_flush_rrd_daemon();
35 $info=rrd_lastupdate(RRDFILE);
38 'last_update' => 'unknown',
40 'error' => rrd_error(),
44 'last_update' => $info['last_update'],
45 'watts' => (float)$info['data'][0],
47 $result['counter'] = ampy_get_counter();
48 send_chunk(json_encode($result));