Exploring Pear registry
You probably know many pear projects like DB, XML-RPC, ... But let's see some PEAR Classes that we don't have the occasion to know : PEAR::Registry. This is class is meant to maintain pear packages in a registry. The registry is a folder under PEAR main folder where we find .reg file for each PEAR package installed on our server.
To start using the PEAR registry we first should create an object PEAR_Registry :
$registry = new PEAR_Registry("c:/php4/PEAR");
Where you note the path to pear packages. Then let's explore some of the functions from PEAR, and the first information that we want to know is whar are the packages installed on my system. You can have this information using te method _packageInfo()
$registry = new PEAR_Registry("c:/php4/PEAR");
$pkgs = $registry->_listPackages();
This function will return a list of installed packages in your system
Array ( [0] => archive_tar [1] => console_getopt [2] => pear [3] => xml_rpc )
Now we can go more further and retrieve more informations about each package, here we'll use the method _packageInfo()
$registry = new PEAR_Registry("c:/php4/PEAR");
$pkgs = $registry->_listPackages();
$pear_html = '';
foreach($pkgs as $k=>$package) {
$info = $registry->_packageInfo($package);
$pear_html .= "
$info[package]
Version $info[version]
Released on $info[release_date]
Release state $info[release_state]
$info[description]
";
}
$pear_html .= '
';
echo $pear_html;
which will give us for example :
| Archive_Tar Version 1.1 Released on 2003-05-28 Release state stable |
This class provides handling of tar files in PHP. It supports creating, listing, extracting and adding to tar files. Gzip support is available if PHP has the zlib extension built-in or loaded. Bz2 compression is also supported with the bz2 extension loaded. |
| Console_Getopt Version 1.2 Released on 2003-12-11 Release state stable |
This is a PHP implementation of "getopt" supporting both short and long options. |
| PEAR Version 1.3.1 Released on 2004-04-06 Release state stable |
The PEAR package contains: * the PEAR base class * the PEAR_Error error handling mechanism * the alpha-quality PEAR_ErrorStack advanced error handling mechanism * the PEAR installer, for creating, distributing and installing packages * the OS_Guess class for retrieving info about the OS where PHP is running on * the System class for quick handling common operations with files and directories |
| XML_RPC Version 1.1.0 Released on 2003-03-15 Release state stable |
This is a PEAR-ified version of Useful inc's XML-RPC for PHP. It has support for HTTP transport, proxies and authentication. |
You can just do a print_r($info); after $info = $registry->_packageInfo($package); to see all details it return as result.
Pear Usage
There is another important information that we could know is the PEAR usage in your system, I just created this parameter to have an idea what I have installed on my system.
$registry = new PEAR_Registry("c:/php4/PEAR");
$pkgs = $registry->_listPackages();
$pear_usage = count($pkgs) * 100 / 137;
echo "Pear usage $pear_usage %";
Well personaly I have only 3% of Pear packages installed on my home server, and probably this is the case of many php users also. So we'll try to go more further next tutorial and explore more exciting and useful things.


