The rrdextension of php was removed from the earlier version of rrdtool two days ago. so is upgraded to the latest rrd. so, when used, it is found that many function calling methods have changed, mainly because the count ($ opts) configuration is canceled, for example, functions such as rrd_create, rrd_fetch, and rrd_update are originally (s... sy
Two days ago, the rrd extension of php was upgraded from rrdtool. so of the old version to the latest rrd. so.
However, during use, it is found that many function calling methods have changed, mainly because the count ($ opts) configuration has been canceled, such as rrd_create, rrd_fetch, rrd_update, and other functions.
Originally, all three parameters (string $ filename, array $ options, count ($ opts) are simplified to two parameters (string $ filename, array $ options ).
However, the headache is that the format of the return value of the rrd_fetch function has all changed, resulting in a completely different format from the existing code.
In the new rrd. so, rrd_fetch returns the following values:
[Php]
Array (4 ){
["Start"] =>
Int (1341834300)
["End"] =>
Int (1341834600)
["Step"] =>
Int (300)
["Data"] =>
Array (2 ){
["Ds0"] =>
Array (1 ){
[1341834600] =>
Float (29875732.323333)
}
["Ds1"] =>
Array (1 ){
[1341834600] =>
Float (139478395.26667)
}
}
}
In the old rrdtool. so, rrd_fetch returns the following values:
[Php]
Array (6 ){
["Start"] =>
Int (1341834300)
["End"] =>
Int (1341834600)
["Step"] =>
Int (300)
["Ds_cnt"] =>
Int (2)
["Ds_namv"] =>
Array (2 ){
[0] =>
String (3) "ds0"
[1] =>
String (3) "ds1"
}
["Data"] =>
Array (2 ){
[0] =>
Float (1073.00666667)
[1] =>
Float (32.9566666667)
}
}
[Php]
[UTC] koubel at seznam dot cz
Thank you, rrd_fetch rewritten, there were a bug in filling the returned array. nowadays all data sources are supported (trunk code ). I made a litte bit BC break, no more ds_cnt, ds_namv keys in result array from fetch. I think these are completely useless.
The two parameters ds_cnt and ds_namv are useless, and the data return format is modified.
Well, the new rrd_fetch is really simple, and there is still time for data, which is very convenient. but what should we do in the transitional stage? The original system cannot be changed in an instant, but the rrd has been upgraded in the background, so we have to provide a temporary solution first.
[Php]
# The returned format of the old version rrd_fetch is different from that of the new version. in the transition phase, you must use the following function to change the returned value of the new version rrd_fetch to the old version to be compatible with the old version.
Function my_rrd_fetch ($ file_path, $ opts, $ count = 0 ){
$ Ret = rrd_fetch ($ file_path, $ opts );
If (! $ Ret)
Return false;
$ Start = $ ret ['start'];
$ End = $ ret ['end'];
$ Step = $ ret ['step'];
$ Ds_cnt = 0;
$ Ds_namv = array ();
$ Data = array ();
$ Tmpdata = array ();
Foreach ($ ret ['data'] as $ key => $ values ){
$ Ds_namv [] = $ key;
$ Ds_cnt ++;
Foreach ($ values as $ time => $ value ){
$ Tmpdata [] = $ value;
} Www.2cto.com
}
$ Count = count ($ tmpdata );
For ($ I = 0; $ I <($ count/2); $ I ++ ){
$ Data [] = $ tmpdata [$ I];
$ Data [] = $ tmpdata [$ I + ($ count/2)];
}
Return array ('start' => $ start, 'end' => $ end, 'step' => $ step, 'DS _ cnt '=> $ ds_cnt, 'ds _ namv' => $ ds_namv, 'data' => $ data );
}
Use my_rrd_fetch to replace the previous rrd_fetch. the function is to change the returned value of the new version of rrd_fetch to the old version for temporary compatibility with the old version of code...
Of course, it is still necessary to change all functions to new functions in the later stage...
Author: Liv2005