Specifications

Advanced PHP Techniques
P
ART IV
370
In this chapter, well look at the network-oriented functions in PHP that enable your scripts to
interact with the rest of the Internet. Theres a world of resources out there, and a wide variety
of protocols available for using them. In this section well consider
An overview of available protocols
Sending and reading email
Using other Web services via HTTP
Using network lookup functions
Using FTP
Using generic network communications with cURL
Overview of Protocols
Protocols are the rules of communication for a given situation. For example, you know the pro-
tocol when meeting another person: You say hello, shake hands, communicate for a while, and
then say goodbye. Computer networking protocols are similar.
Like human protocols, different computer protocols are used for different situations and appli-
cations. We use HTTP, the Hypertext Transfer Protocol, for sending and receiving Web pages.
You will probably also have used FTP, file transfer protocol, for transferring files between
machines on a network. There are many others.
Protocols, and other Internet Standards, are described in documents called RFCs, or Requests
for Comments. These protocols are defined by the Internet Engineering Task Force (IETF). The
RFCs are widely available on the Internet. The base source is the RFC Editor at
http://www.rfc-editor.org/
If you have problems when working with a given protocol, the RFCs are the authoritative
source and are often useful for troubleshooting your code. They are, however, very detailed,
and often run to hundreds of pages.
Some examples of well-known RFCs are RFC2616, which describes the HTTP/1.1 protocol,
and RFC822, which describes the format of Internet email messages.
In this chapter, we will look at aspects of PHP that use some of these protocols. Specifically,
we will talk about sending mail with SMTP, reading mail with POP and IMAP, connecting to
other Web servers via HTTP and HTTPS, and transferring files with FTP.
22 7842 CH17 3/6/01 3:39 PM Page 370