Weather Is Back

Jan 1, 2006

I finally added a weather widget back to this site. I am using a new method, which is in some ways better and some ways worse. The new method takes advantage of an XML feed made available by the National Weather Service. The old method displayed weather conditions by using PHP and MySQL. It was kind of a hack which scraped data off the NWS website and used PHP regular expressions. It was highly susceptible to getting broken just about anytime the NWS website changed which was fairly often. The old script also stopped working when my host sensibly disabled allow_url_fopen. I could’ve changed the old script to use PHP’s CURL functions instead, but I never had the time.

The new method grabs the XML from the NWS and uses PHP and Cron to parse, store and display the data. The basic feeds provide somewhat limited information. It is mainly current conditions, so I can’t display future conditons like I used to. Right now there is a way to access more data, but it is far more complex and requires making SOAP requests (Simple Object Access Protocol).

One of the reasons I waited so long to put weather back was because the method to parse XML using PHP 4 seemed way more complicated than it should be. In PHP 5 there is a much simpler method, using the SimpleXML functions.

A big kudos has to go out to my host, Dreamhost, for making it unbelievably easy to switch to PHP 5 anytime you want. They have set up a mechanism that allows you to switch from PHP 4 to PHP 5 in minutes, with the push of a button. What makes this even more awesome is I’m on a shared hosting plan. With the majority of hosts, you’re going to be stuck on PHP 4 until they make their changes across the board. Very impressive Dreamhost, but then again I’ve come to expect good stuff from them.