Our simple example above left a few loose ends - caching and error checking. It's highly recommended that you cache your AWS results. There's a performance benefit, and you don't want to risk breaking Amazon's "1 query per second" rule, especially when you get popular with Google. There's an excellent PEAR packaged called Cache Lite that will help us out. It is small, stable, very fast, and easy to setup. Follow the instructions, but basically all you have to do is save the Cache Lite files to a directory above your web root and create a separate directory where the actual cached files will be stored.
You could also use phpCache, a full tutorial on how to implement it can be found here.
Finally, we want to check for two basic errors:
Unfortunately, you can't expect 99% uptime with AWS. I know, I said AWS runs on autopilot,
but there are times when the service isn't as responsive as you'd hope. Test to see if AWS is
down by searching for "xml" in the XML document. (Don't search for an empty string because
sometimes AWS returns a generic error message.) For a valid call to AWS that returns no
products, such as a bad keyword search, look for the
Destination-USA is ready to launch! The function to build the XML link to AWS
is contained in an include file for portability. Notice in the function file
the three arrays which store common attributes used in the XML link. Observe
which attributes are passed via the querystring for each page. The caching and
error checking have been implemented. As you click around the site, you may
notice some books are missing data. This is common with AWS, not every product
has an official description or customer reviews. There is a data error check
example in the Product Page (product.php) for the
Below, you can launch the site and view the source of each page. Each link opens a new window:
There are a number of improvements that could be made to Destination-USA. The URLs could become search engine friendly. You could read up in the Developer's Kit and create a local shopping cart. A more ambitious project would be to download the AWS data into a local database, that way you would have total layout freedom (you wouldn't be stuck on the 10 item limit) and have improved protection from AWS outages. The possibilities are endless.