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');
10 $speed=@(int)$_GET['speed'];
15 header("Content-Type: text/json");
16 header("Transfer-Encoding: chunked");
20 // Send chunk to browser
21 function send_chunk($chunk)
23 // The chunk must fill the output buffer or php won't send it
24 $chunk = str_pad($chunk, 4096);
26 printf("%x\r\n%s\r\n", strlen($chunk), $chunk);
31 exec("/usr/bin/rrdtool flushcached --daemon ".RRDSOCK." ".RRDFILE);
33 $info=rrd_lastupdate(RRDFILE);
36 'last_update' => 'unknown',
38 'error' => rrd_error(),
42 'last_update' => $info['last_update'],
43 'watts' => (float)$info['data'][0],
45 send_chunk(json_encode($result));