An Open Access Peon

25 September 2006

PHP gd and Perl gd segfaulting

I make a lot of use of GD (through charts) in my services, which also use a mix of Perl and PHP scripts. Unfortunately PHP defaults to using an internal copy of the GD library that, when used, causes a segfault if GD is also used by mod_perl (which will use the system GD library). The segfault is the result of attemping to use two versions of the GD library at once.

The solution to this problem is to use the system GD library in PHP. I use RedHat enterprise on my servers and want to use RPMs to allow ease of keeping up to date with bug fixes. Fortunately it's pretty easy to modify the RPM source to fix this isolated problem, without having to install a compiled PHP.

Download and install the source RPM (NB make sure you install the correct version):
up2date --get-source php
rpm -ivh /var/spool/up2date/php-*.src.rpm


Change to the rpm source build directory:
cd /usr/src/redhat


Create a new file called 'php.spec.patch' containing this:

--- php.spec.orig 2006-09-25 12:00:23.000000000 +0100
+++ php.spec 2006-09-25 12:00:44.000000000 +0100
@@ -433,7 +433,7 @@
--with-exec-dir=%{_bindir} \
--with-freetype-dir=%{_prefix} \
--with-png-dir=%{_prefix} \
- --with-gd=shared \
+ --with-gd=shared,/usr \
--enable-gd-native-ttf \
--without-gdbm \
--with-gettext \


Patch the php.spec file (-l ignores whitespace):
patch -l SPECS/php.spec <php.spec.patch


Build the binary RPM (will take a while):
rpmbuild -bb SPECS/php.spec


Install the new php-gd rpm:
rpm -Uvh RPMS/php-gd-*.rpm


You may want to add php-gd to the skip-list in /etc/sysconfig/rhn/up2date, otherwise if RedHat update php it'll cause your Web server to seg fault.

13 September 2006

Javascript Graphs

Citebase now has the Correlation Generator again, which was always in need of some fixing.

I've replaced the Java-based charts with Javascript ones, based on Emil A Eklund's Chart Widget. The advantages of the Javascript charts are that they load quicker (not requiring a Java VM) and that it's much easier for me to customize them to my needs.

While the chart widget is compatible with IE and Safari I haven't bothered to put in all the wrapper code for the AJAX and element searching in my glue code - I figure this is such a specialist tool it's not unreasonable to expect users to download Firefox.

While I'm happy enough with the implementation for the Generator to be published, the charts could really do with a mechanism to zoom - most of the interesting stuff in citation and download data happens very quickly, hence can be eclipsed by the 'long-tail'.

Regardless of the current drawbacks, I think it looks and works pretty well.