Specifications

The curl_setopt() function takes three parameters. The first is the session handle, the second
is the name of the parameter to set, and the third is the value to which you would like the para-
meter set.
In this case we are setting two options. The first is the URL that we want to connect to. This is
the CURLOPT_URL parameter. The second one is the file where we want the data from the con-
nection to go. If you dont specify a file, the data from the connection will go to standard
outputusually the browser. In this case we have specified the file handle of the output file we
just opened.
When the options are set, we tell cURL to actually make the connection:
curl_exec ($ch);
Here, this will open a connection to the URL we have specified, download the page, and store
it in the file pointed to by
$fp.
After the connection has been made, we need to close the cURL session, and close the file we
wrote to:
curl_close ($ch);
fclose($fp);
Thats it for this simple example.
You might find it worthwhile to look at the Snoopy class, available from
http://snoopy.sourceforge.net/
This class provides Web client functionality through cURL.
Further Reading
Weve covered a lot of ground in this chapter, and as you might expect, theres a lot of material
out there on these topics.
For information on the individual protocols and how they work, you can consult the RFCs at
http://www.rfc-editor.org/
You might also find some of the protocol information at the World Wide Web Consortium
interesting:
http://www.w3.org/Protocols/
You can also try consulting a book on TCP/IP such as Computer Networks by Andrew
Tanenbaum.
Using Network and Protocol Functions
C
HAPTER 17
17
USING NETWORK
AND
PROTOCOL
FUNCTIONS
389
22 7842 CH17 3/6/01 3:39 PM Page 389