Team LiB
Previous Section Next Section

PHP Programming Libraries for HTTP Work

When you're working with content over the network via HTTP, you will quickly find that although PHP makes certain things easy, it doesn't make them complete. Specifically, although the PHP Streams facility allows you to easily access HTTP resources as if they were files, it doesn't allow you to access meta information such as the HTTP response codes from an HTTP transaction. Nor do the built-in PHP commands allow you to set useful properties of the HTTP transaction, such as the user agent.

To access this type of meta information, you need to turn to a more advanced approach to HTTP programming. There are several candidates for this, including Curl, Snoopy, and HttpClient.

Curl is a PHP binding for the standard Unix Curl libraries that provide network TCP/IP input and output. Although Curl has the advantage of being built in to the PHP language that is convenient, easy, and fast, Curl is not generally a standard part of most PHP installations. And although Curl can be easily built in to PHP, it requires recompiling PHP, which is something that not all PHP developers can do. Specifically, if you are working in a shared hosting environment, your ISP may not be able (or willing) to recompile PHP with Curl support. More information on Curl can be found at

http://php.net/manual/en/ref.curl.php

Curl is an official part of PHP, albeit one that isn't commonly installed, but there also are third-party HTTP programming librarieswritten entirely in PHPthat can be used without any changes to your PHP installation. Although these libraries aren't as fast as the Curl libraries, for most applications they are more than sufficient. Additionally their ease of use, coupled with the capability to be deployed to any PHP installation, is a significant argument in their favor. Two of these libraries are Snoopy and HttpClient.

Snoopy, at http://snoopy.sf.net/, is an older library that, although fully functional, is no longer being actively maintained. It provides full HTTP functionality with a simple object-oriented interface; however, its documentation is somewhat lacking. HttpClient, at http://scripts.incutio.com/httpclient/, is a newer library, which is both being maintained and has quite good documentation.

For the examples in this chapter, the HttpClient library will be used.

    Team LiB
    Previous Section Next Section