Tuesday, October 2, 2007

Lab 2 - List Server

After climbing over the learning curve of the first lab, lab 2 was a piece of cake. Speaking of cake, I switched to PHP for this lab. I had my fill of mod_python for a little while, I may switch back to it for the next lab, but I haven't decided.

I used Smarty for templating. It's one of the only 2 templating systems I've used for PHP (the other being the one built into PHP itself), and I prefer Smarty. It has plenty of features, is pretty lightweight and performs very well after the templates have been compiled and cached. Getting PHP and Smarty working was trivial, I had a little more difficulty getting JSON working.

I was able to get my code written quickly on my development machine. I used file_get_contents to retrieve the JSON data, which reads/stores the contents of a file or the response from an HTTP GET request as a string. PHP's JSON library has two methods json_encode and json_decode. By means of a flag, you can decode a JSON message into a PHP object, or an associative array. I chose the associative array, and used a template to generate my XML.

The only difficulty I had was setting up PHP's JSON library on my EC2 server. The library comes bundled with PHP 5.2, but not with the previous versions. And there is no yum installer for PHP 5.2 on FC4. yum install php_json did the trick in the end (took me about 2 hours to get there).

I used mod_rewrite to map our URL interface to my backend. It worked well once I got my regular expressions correct.

P.S. - My bill for September was only $1.81.

No comments: