Web Development

Simplify your PHP coding with 10 network programming PEAR classes

The PHP Extension and Application Repository (PEAR) has a number of packages that can significantly simplify your network programming projects. This document lists 10 PEAR packages of specific interest to developers working in the network programming realm and explains how they should be used.

This article is also available as a TechRepublic download.

Network programming is an area many developers find troublesome, especially if most of their experience lies in the much "softer" world of Web application scripting. If you're one of these developers, though, you shouldn't let this fact keep you up at night, because PEAR, the PHP Extension and Application Repository, has a number of packages that can significantly simplify your network programming projects. These packages provide a robust, well-tested code base, and also save you the time and effort you would otherwise spend in "rolling your own" code. You can't beat the price either -- they're free!

This document lists 10 PEAR packages (Table A) of specific interest to developers working in the network programming realm. Take a look, and try them out. You never know, you might find something that solves a problem you're currently facing!

Note: You can install PEAR packages directly from the Web, by following the instructions provided.

Table A


Package Name

Description

URL

Net_Server

This module provides an abstraction layer for PHP's socket API, making it easy to create full-featured daemon applications. It supports server features like forking, access control and transactions over TCP, and can easily be extended through sub-classing.

Use this module when you need to create a highly-customized, extensible server daemon.

Net_Server

Net_IPv4

This module provides miscellaneous tools for working with IPv4 addresses. Some of its functions include converting IP addresses in dotted-quad notation to long integers (or the other way around); validating IP address syntax; parsing addresses and netmasks; and calculating network information from IP addresses and netmasks.

Use these functions when you need to manipulate IP addresses, typically for numerical calculations or to "guess" network address information.

Net_IPv4

Net_DNS

This module provides an interface to the DNS system, allowing you to perform sophisticated DNS queries on a remote host through a PHP application. The module also provides OOP access to different segments of a DNS response.

Use this module when you need to run DNS queries, like looking up nameservers and MX records, or performing zone transfers.

Net_DNS

Net_POP3

This module provides routines to connect to, and perform transactions with, a POP3 server through PHP. It supports listing and deleting messages, as well as APOP authentication and DIGEST/CRAM security.

Use this module when you need to build a secure PHP-based POP3 email client.

Net_POP3

Net_SMTP

This module provides a low-level interface to creating and transmitting email messages using the SMTP protocol. You can use it to create an email message in components, connect to and transact with a mail server, and send the result out over a network. Several authentication methods (DIGEST-MD5,CRAM-MD5, LOGIN and PLAIN) are supported.

Use this module when you need greater flexibility than that provided by PHP's built-in mail functions, usually to directly transact with a non-standard SMTP server.

Net_SMTP

Net_FTP2

This module provides a wrapper around the FTP protocol, making it possible to create an FTP client application in PHP. It supports PASV transactions, ASCII and binary file transfers, and most common FTP file operations on the remote server.

Use this module when you need to perform an FTP file upload or download through your PHP application.

Net_FTP2

HTTP_Client

This module provides an interface for creating HTTP clients. It provides an object-oriented interface to send HTTP requests and decipher HTTP responses through PHP. It also supports proxies, cookies and HTTP redirection, all of which come in handy when creating HTTP clients to transact with Web servers.

Use this module when you need to build an HTTP client to interact with a Web server.

HTTP_Client

Net_Portscan

This module provides an API for scanning ports of a remote host. It can be used to check one or more ports for active services, or to retrieve the service associated with a particular port.

Use this module when you need to test if a particular service is running on a remote host, usually when performing Web-based diagnostics.

Net_Portscan

Net_GeoIP

This module provides routines to identify the precise geographical location (city and country) of incoming HTTP client requests, using an external database.

Use this module when your application needs IP geo-location, typically when targeting ad banners by country.

Net_GeoIP

Net_Wifi

This module provides a wrapper around command-line tools to detect available wireless networks and retrieve information about them.

Use this module when your PHP application needs to find and connect to wireless networks.

Net_Wifi

1 comments
Mark W. Kaelin
Mark W. Kaelin

What other PEAR packages do you find most useful?

Editor's Picks