Creating PHP bindings for RRDTool
Posted in Graphing Solutions, Technical Tidbits on October 18th, 2009 by steven – Be the first to commentBackground
PHP is a very popular language for web development. Providing bindings for directly calling rrdtool within PHP provides a simple and efficient means of providing a high-level scripting interface into the data management and display capabilities of rrdtool. The stock installation of rrdtool does not provide any support for PHP so bindings must be created for it manually.
Setup
- Download the php_rrdtool archive from the contributions directory of the RRDTool site.
- Extract the archive contents into the
/usr/include/php/extdirectory.sudo tar xzvf php_rrdtool.tar.gz -C /usr/include/php/ext - Change the owner and group to “root” and “wheel”.
sudo chown -R root:wheel /usr/include/php/ext/rrdtool - Navigate to the newly created rrdtool directory.
cd /usr/include/php/ext/rrdtool - Generate the configuration files for the PHP bindings.
sudo phpize - Execute the newly-generated configuration script for the PHP bindings. Note that the
--with-rrdtoolargument takes as its value the “root” directory where the various rrdtool files are located. If installed using the default values supplied by the MacPorts utility, the “root” directory would be/opt/local.sudo ./configure CFLAGS="-fnested-functions" --with-php-config=/usr/bin/php-config --with-rrdtool=/opt/local - Make the php rrdtool extension.
sudo make - Install the php rrdtool extension. Make a note of the directory into which the extension was deployed.
sudo make install - Make a backup copy of the
/etc/php.inifile for safety. If the file does not yet exist, then copy the/etc/php.ini.defaultinstead.sudo cp php.ini php.ini.origor
sudo cp php.ini.default php.ini - Edit the
/etc/php.inifile and alter the value of theextension_dirvariable to the deployment directory (noted in Step 8).extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20060613/" - Edit the
/etc/php.inifile and a new variable under the Dynamic Extensions section specifying the rrdtool extension.extension=rrdtool.so - Restart the apache server to load the new configuration information.
sudo apachectl restart - Verify the rrdtool extension can be loaded from within PHP.
php -m
Special Notice for Mac OS X Users
With the evolution from 32-bit to 64-bit architectures in progress, it may arise that the rrdtool module is accessible through some mechanisms and not through others. For example, it has been observed on some hardware/operating systems that the module will load properly when referenced directly by the PHP interpreter (i.e. php -m), but is not accessible when referenced within a web page served by Apache (i.e. not listed as part of the phpinfo() output). This situation is most likely due to Apache running in 64-bit mode while the PHP interpreter and associated extensions are running in 32-bit mode. If this situation arises, then the suggested solution is to force Apache to run in 32-bit mode.