[rrd-users] Re: How can I use RRDTool with PHP?

D. Walsh info at daleenterprise.com
Mon Jun 5 15:06:55 MEST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Jun 5, 2006, at 06:20 , Sepp Wang wrote:

>  |Following is my source code:
> It can work, but always return the image's width and heigth.
> How can I discard it?
> Also, is there a better solution use RRDTool with PHP?
> Sepp

Yes there is a much easier way in PHP to use RRDTool, see the  
following links to see that RRDTool functions can be embedded in PHP.

http://www.daleenterprise.com/amavis-stats
http://www.daleenterprise.com/info.php#module_rrdtool

I rewrote the PHP module to properly support rrdtool 1.0.x and 1.2.x   
in PHP4 and PHP5, this is mentioned on the list several time a month  
yet the same question is asked.

You don't need to rebuild PHP to get this module included in PHP, you  
can build it as a shared module and add the module to the load module  
section in php.ini


Building as shared is as simple as downloading the module source, un  
pack it, cd into the module source directory, issue the following  
commands
If you have RRDTool installed with a prefix of /usr or /usr/local you  
can use "--with-rrdtool" as it will locate the the library.

For this example rrdtool 1.2.12 is install with a prefix of /usr/ 
local/rrdtool-1.2.12, the install prefix is the important information.

phpize
./configure --with-rrdtool=/usr/local/rrdtool-1.2.12
make
make install

Edit php.ini and add the module to the extension load section,  
restart apache and that should be it.

> <?php
> $time=date("Y/m/dH\\\:i\\\:s");
>
> $cmd="/usr/local/bin/rrdtoolgraphtest.png".
> "DEF:inoctets=test.rrd:input:AVERAGE".
> "DEF:outoctets=test.rrd:output:AVERAGE".
> "COMMENT:\"MaxAverageMinNow\\n\"".
> "LINE1:inoctets#00FF00:\"Intraffic\"".
> "GPRINT:inoctets:MAX:\"%8.0lf\"".
> "GPRINT:inoctets:AVERAGE:\"%8.0lf\"".
> "GPRINT:inoctets:MIN:\"%8.0lf\"".
> "GPRINT:inoctets:LAST:\"%8.0lf\"".
> "LINE1:outoctets#0000FF:\"Outtraffic\"".
> "GPRINT:outoctets:MAX:\"%8.0lf\"".
> "GPRINT:outoctets:AVERAGE:\"%8.0lf\"".
> "GPRINT:outoctets:MIN:\"%8.0lf\"".
> "GPRINT:outoctets:LAST:\"%8.0lf\"".
> "--title\"Traffic\"-v\"Bytespersecond\"COMMENT:\"LastUpdated\:$time 
> \"".
> "-s`date-v-1d+%s`--imginfo'<IMGSRC=\"%s\"WIDTH=\"%lu\"HEIGHT=\"%lu 
> \"ALT=\"Demo\">'";
>
> $fp=popen($cmd,"r");
> fpassthru($fp);
> ?>
> <html>
> <head><title>RRDToolGraphTest</title></head>
> <body>
> </body>
> </html>
> |
>
>
> --

This really isn't the correct syntax to achieve your goal as it  
doesn't look like rrd_graph is never called to update the image and  
your html doesn't look like it's capable of serving the image other  
than you are passing it raw before any headers are sent.

- -- Dale


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (Darwin)

iD8DBQFEhCxwgKKwRgpESgMRAl63AJ9pHoHKoDoxJzAUigqEgb46mEAeEQCghwS3
wWZ2V7djuoCvtejO4ijhxkM=
=uRVz
-----END PGP SIGNATURE-----

--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://lists.ee.ethz.ch/rrd-users
WebAdmin    http://lists.ee.ethz.ch/lsg2.cgi



More information about the rrd-users mailing list