Creating PHP bindings for RRDTool

Background

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

  1. Download the php_rrdtool archive from the contributions directory of the RRDTool site.
  2. Extract the archive contents into the /usr/include/php/ext directory.

    sudo tar xzvf php_rrdtool.tar.gz -C /usr/include/php/ext

  3. Change the owner and group to “root” and “wheel”.

    sudo chown -R root:wheel /usr/include/php/ext/rrdtool

  4. Navigate to the newly created rrdtool directory.

    cd /usr/include/php/ext/rrdtool

  5. Generate the configuration files for the PHP bindings.

    sudo phpize

  6. Execute the newly-generated configuration script for the PHP bindings.  Note that the --with-rrdtool argument 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

  7. Make the php rrdtool extension.

    sudo make

  8. Install the php rrdtool extension.  Make a note of the directory into which the extension was deployed.

    sudo make install

  9. Make a backup copy of the /etc/php.ini file for safety.  If the file does not yet exist, then copy the /etc/php.ini.default instead.

    sudo cp php.ini php.ini.orig

    or

    sudo cp php.ini.default php.ini

  10. Edit the /etc/php.ini file and alter the value of the extension_dir variable to the deployment directory (noted in Step 8).

    extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20060613/"

  11. Edit the /etc/php.ini file and a new variable under the Dynamic Extensions section specifying the rrdtool extension.

    extension=rrdtool.so

  12. Restart the apache server to load the new configuration information.

    sudo apachectl restart

  13. 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.

Leave a Reply