Quality with a capital P

The pdf extension library shipped with PHP-4.4.7 doesn’t work, and it’s a known “non-bug”. I’m not sure why they still ship the broken library. I installed the PECL version, via pear (my first time trying that), and that was pretty painless. It created a pdf.so and put it in some long /usr/local/lib path. So I figured, now I can just load it with:

dl("/usr/local/lib/php/extensions/no-debug-non-zts-20020429/pdf.so");

right? Wrong:

Warning: dl(): Unable to load dynamic library './/usr/local/lib/php/extensions/no-debug-non-zts-20020429/pdf.so' - Cannot open ".//usr/local/lib/php/extensions/no-debug-non-zts-20020429/pdf.so" in /root/test.php on line 7

I have “./” as my extension_dir in php.ini. For some reason, the code for dl doesn’t recognize that I’m specifying a full path, though. The fix, according to posters on http://www.php.net/dl, is to prepend a sufficient number of ../’s to the path before calling dl() !

The resulting code (with helpful dpk-comments) is:
<?php
// This is required, and is astounding.
$dotdots = preg_replace ('/\/([^\/]+)/’, ‘../’, dirname(__FILE__));
$dlpath = $dotdots . ‘/usr/local/lib/php/extensions/no-debug-non-zts-20020429/pdf.so’;
dl($dlpath);
// My brain still hurts.
$p = PDF_new();
?>

Leave a Reply