I've decided to retire this blog — I don't really see myself updating it any time soon, and haven't for over two years anyway. I intend to leave the content on-line for the forseeable future, but have converted it to a static site. As a result, dynamic things like search and comments aren't really going to work.

You can find me on Twitter or on Google+ if you like. Alternatively, I'm usually on IRC as LawnGnome on Freenode.

Thanks for reading!


I’ve seen three people ask a variation of how can I get a list of installed PEAR packages from within my PHP script in the last few weeks on IRC, and two just in the last day. Because I’m a helpful sort, here’s a little morsel of code that will do just that:

include 'PEAR/Registry.php';

$reg = new PEAR_Registry;
foreach ($reg->listPackages() as $package) {
    print "$package\n";

This should work with pretty much any version of PEAR.

(Update: Ken has a nifty bit of code in the comments to check for a specific installed version of a package.)

5 Responses to “$pear->list”

  1. Daniel O'Connor Says:

    Oh, that beats PEAR_Info

  2. PHPDeveloper.org Says:

    Adam Harvey’s Blog: $pear->list…

  3. developercast.com » Adam Harvey’s Blog: $pear->list Says:

    [...] Harvey has a (very) quick post with a hint for PEAR users out there – how to get a list of installaed packages on the system [...]

  4. Ken Guest Says:

    This inspired me to find a way to check if certain packages of a specific version are installed:

    include ‘PEAR/Registry.php’;
    $reg = new PEAR_Registry;

    $packages = array(array(“PEAR”, “1.6.2″),
    array(“Date”, “1.4.7″),
    array(“Date_Holidays”, “0.17.1″),
    array(“Validate_IE”, “0.2.1″));

    foreach($packages as $package) {
    $pkg = $reg->getPackage($package[0]);
    $version = $pkg->getVersion();
    echo “{$package[0]} – {$package[1]} – “, version_compare($version, $package[1], “>=”) ? “OK”: “BAD”, “\n”;

  5. 網站製作學習誌 » [Web] 連結分享 Says:

    [...] $pear->list [...]