PEAR:: Classes Worthy Of Attention

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, January 26, 2009

Follow me on Twitter as @mattiasgeniar

PEAR offers an excellent framework for re-usable PHP components. A wide range of PEAR classes is available, from XML Parsers to Captcha’s and Mail components.

They’re all easy to install, and have extensive documentation available so you can get started right away. Here’s a list of some of the better, and probably lesser known ones.

  • PEAR::Mail

    PEAR’s Mail package defines an interface for implementing mailers under the PEAR hierarchy. It also provides supporting functions useful to multiple mailer backends. Currently supported backends include: PHP’s native mail() function, sendmail, and SMTP. This package also provides a RFC822 email address list validation utility class.

  • PEAR::XML_Parser

    This is an XML parser based on PHPs built-in xml extension. It supports two basic modes of operation: “func” and “event”. In “func” mode, it will look for a function named after each element (xmltag_ELEMENT for start tags and xmltag_ELEMENT_ for end tags), and in “event” mode it uses a set of generic callbacks.

  • PEAR::MIME_Type

    Provide functionality for dealing with MIME types, such as auto-detecting MIME type on files.

  • PEAR::Net_Socket

    Net_Socket is a class interface to TCP sockets. It provides blocking and non-blocking operation, with different reading and writing modes (byte-wise, block-wise, line-wise and special formats like network byte-order ip addresses). It provides the base class for other popular PEAR-classes such as Net_SMTP and HTTP_Request.

  • PEAR::Archive_Tar

    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.

The list of available packages goes on for miles, and includes a Facebook package, a Number-to-Words convertor, Command line Argument Parser, CAPTCHA generator, Barcode Generator, … Too much to mention!

For installation instructions, I’ll refer you to the following two posts:

I’m interested to know what PEAR packages you’re using, and why. Where do you draw the line between writing your own classes, and switching to PEAR’s?



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.