rrd.so更新导致rrd_fetch返回值变更,与旧版不兼容
前两天把php的rrd extension从旧版本的rrdtool.so升级到了最新的rrd.so
但是使用时发现很多函数的调用方式都变了,主要是都取消了count($opts)的配置,比如rrd_create、rrd_fetch、rrd_update等函数
原本都是( string $filename , array $options , count($opts))三个参数,现在都简化成了( string $filename , array $options)两个参数
但头疼的是rrd_fetch这个函数的返回值格式整体都变掉了,导致和已有的代码完全不一样。
新的rrd.so中,rrd_fetch返回值:
[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)
}
}
}
旧的rrdtool.so中,rrd_fetch返回值:
[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 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.
大神觉得ds_cnt、ds_namv这两个参数完全没用,并且还修改了data的返回格式
好吧,新的rrd_fetch确实挺简单,而且还有了数据对应的时间,非常方便,但是过渡阶段怎么办呢?原始系统没办法瞬间改完,但后台rrd已经升级完了,没办法,只好先搞个临时解决方案
[php]
#旧版本的rrd_fetch返回格式与新版本不同,过渡阶段需要用下面的函数将新版本rrd_fetch的返回值,改成旧版本的格式,才能兼容旧版本代码
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
$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);
}
用上面的my_rrd_fetch来替换以前的rrd_fetch,功能就是将新版的rrd_fetch的返回值改成旧版的返回,用于临时兼容旧版本代码...
当然后期还是要慢慢的都改成新函数才可以...
作者:Liv2005

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide
