一个展示此方法用法的示例(在 php 版本 5.6.30 中测试)
class Rrd{
public function getData($id , $start , $end)
{
$step = 300 ;
$rrdFile ="/path/to/file/'.$id.rrd";
try{
$options = ["--start", $start , "--end", $end ,"-- step",$step,"DEF:out=$rrdFile:name:AVERAGE", "XPORT:out:test"];
$result = rrd_xport($options);
$datas = $result['data'][0]['data'];
foreach($datas as $data => $value){
if( is_nan($value) === true ) $value = 0 ;
$output[] = [$data=>$value] ;
}
return json_encode($output);
}catch (Exception $e){
dd($e->getMessage());
}
}
}