Search code examples
phppeclrrdtool

PHP Uncaught Error when testing RRD support


I have this PHP file which Im using to test RRD support:

<?php
$result=rrd_fetch( "/ang.rrd", array( "AVERAGE", "--resolution", "60", "--start", "-1d", "--end", "start+1h" ) );

foreach ( $result["data"]["myfield"] as $key => $value )
{
    echo "At timestamp $key, the value for myfield is $value.\n";
}
?>

If I browse to the file I get the following:

PHP Fatal error:  Uncaught Error: Call to undefined function rrd_fetch() in /var/www/html/graph.php:2\nStack trace:\n#0 {main}\n  thrown in /var/www/html/graph.php on line 2

and if I try to run the file on the command line I get the following:

PHP Notice:  Undefined index: myfield in /var/www/html/graph.php on line 4
PHP Warning:  Invalid argument supplied for foreach() in /var/www/html/graph.php on line 4

Im not sure why. Could somebody shed some light on why this is happening please?


Solution

  • The answer lies in your error message:

    Call to undefined function rrd_fetch

    The issue is that the rrd functions are not provided by default. They have to be added by install the rrd pecl package.

    Try installing rrd and retrying your code: https://pecl.php.net/package/rrd

    rrd documentation: http://www.php.net/rrd