Installing & Using PEAR
The PHP Extension and Application Repository (PEAR) is an open source structured library of packages for PHP developers. These packages provide routines which solve problems PHP developers regularly face: sending structured e-mail (such as an HTML attachment), interacting with different databases from a single script, error handling, recovery and logging.
The base installation of PEAR is shipped with PHP itself. The programmers working on PEAR have developed a method of installing new packages and keeping your existing installation up-to-date, called the PEAR package manager.
PEAR package manager
If you are using a version of PHP prior to 4.3, you will need to install the PEAR package manager. UNIX users can run the following command:
lynx -source http://go-pear.org/ | /path/to/php
This downloads the source of the page at http://go-pear.org and runs it with the PHP binary (replace /path/to with the path to PHP on your system).
Windows users should go to the specified URL and save the page as ‘pear.php’ then run the following in DOS:
The installation process creates a program called pear (this program is shipped with PHP 4.3), which is the PEAR package manager. Once installation is complete, you are ready to interact with the PEAR package manager.
Using the package manager
The PEAR package manager requires Internet access to download and install new packages. Make sure you are connected to the Net before proceeding. Before downloading new packages, it is useful to see which PEAR packages are installed. To do so, run:
This prints a formatted list of the package names, their version, and their status (whether the release is stable, in beta or otherwise). For basic installations, this list is quite short. To see all available PEAR packages, run:
To install a package on the remote list, type:
pear install <package name>
For example, a package which is not installed by default is Mail_Mime. To install Mail_Mime type:
pear install Mail_Mime
You can find out more about Mail_Mime with the following command:
pear remote-info Mail_Mime
Now we will look at some of the other packages in the PEAR library.
The packages required for this column are available from www.pear.php.net.
To install them into your local PHP system, copy all packages from the PEAR site into a temporary directory, then type:
$ pear install
Where <package filename> is the filename of the package you are installing. The packages are stored in tar gzipped format, so you may get an error like this:
The extension ‘zlib’ couldn’t be found.
Please make sure your version of PHP was built with ‘zlib’ support.
If so, you will need to rebuild PHP passing the ‘--with-zlib’ argument to configure (see the INSTALL file in the PHP source archive).
Logging can be a very important part of application development, debugging and management. The PEAR Log package provides a convenient mechanism for doing this in a standardised manner.
Line 4 creates an instance of the object we’re interested in: namely, a file-based logging object (argument one) that logs to log.txt (argument two). Line 5 buffers a log message inside the object and line 6 writes the buffer to log.txt. This last point is very important: if you do not call the WriteOut() method the log message(s) will be lost.
There are many more packages for you to explore at http://pear.php.net
|All times are GMT +5.5. The time now is 17:44.|