rrd.so update causes Rrd_fetch return value change, incompatible with legacy _php tutorial

Source: Internet
Author: User
Tags rrd rrdtool
The previous two days upgraded PHP's RRD extension from an older version of rrdtool.so to the latest rrd.so


However, it is found that many functions are changed in the way they are called, mostly eliminating the configuration of Count ($opts), such as Rrd_create, Rrd_fetch, rrd_update, etc.
Originally (string $filename, array $options, COUNT ($opts)) Three parameters are now simplified to (string $filename, array $options) two parameters


But the headache is rrd_fetch. The return value format of this function has been completely changed, resulting in a complete difference from the existing code.
In the new rrd.so, the Rrd_fetch return value:
[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, the Rrd_fetch return value:
[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]
[2011-03-02 04:26 UTC] koubel at seznam dot cz
Thank you, Rrd_fetch rewritten, there were a bug in filling the returned array. Nowadays all data sources is 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 is completely useless.


The great God felt ds_cnt, DS_NAMV These two parameters are completely useless, and also modified the return format of data


Well, the new Rrd_fetch is quite simple, and the time for the data corresponds is very convenient, but what about the transition phase? The original system has no way to change the instant, but the background rrd has been upgraded, no way, had to make a temporary solution


[PHP]
#旧版本的rrd_fetch返回格式与新版本不同, the transition phase needs to use the following function to change the return value of the new version Rrd_fetch to the old version, in order to be compatible with the old version code
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)];
}


The return array (' start ' = $start, ' end ' = $end, ' step ' = $step, ' ds_cnt ' = $ds _cnt, ' DS_NAMV ' and $ds _NAMV, ' Data ' = $data);
}

Replace the previous rrd_fetch with the above My_rrd_fetch, the function is to change the new version of the Rrd_fetch return value to the old version of the return, for temporary compatibility with the old code ...


Of course, later or slowly to change into a new function can ...
Author: Liv2005

http://www.bkjia.com/PHPjc/478110.html www.bkjia.com true http://www.bkjia.com/PHPjc/478110.html techarticle The previous two days to the PHP rrd extension from the old version of the rrdtool.so upgrade to the latest rrd.so but when used to find a lot of functions are changed, mainly the count ($opts) to cancel the match ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.