Sunday, August 19, 2007

AJAX, PHP & MySQL

After playing around with writing some Google Gadgets, I got to see how easy it is to create pages with AJAX. As a result, I spent the last several weeks adding MySQL to our setup. All status from devices in starCOMUltra are mirrored to a MySQL database. xAP Floorplan scripts have been changed to use MySQL for checking status instead of querying the starCOMUltra COM object directly. It adds an extra layer, but this should make the system more robust as MySQL is more capable to scale as the number of queries grows. It will also allow other apps to keep functioning without erroring out (albeit with stale data) when I take down sCU to do some maintenance.

One thing that can make the number of queries grow is building web pages with AJAX. I've been re-writing our house floorplan control page to present the state of the house updated every 10-15 seconds. Since it pulls data from MySQL instead of the sCU COM object, it leaves sCU to respond to more immediate needs like turning on lights, etc. Using AJAX, I'm reducing the load on the web server since the page no longer does an HTTP refresh. The screen is updated seamlessly since the page doesn't reload entirely and that improves the user experience. I've also converted our TiVo control pages to AJAX so they no longer have the annoying refresh after clicking a button.

This required a move of many pages to Apache instead of IIS, so I'm running both servers. IIS serves ASP and Apache serves AJAX with PHP. This works out well because it offloads IIS which isn't as robust a server.

Overall, this is working out to be a great improvement for our system making it more stable and robust. It's also been a great opportunity to learn about and use AJAX, PHP and MySQL in a real application - much better than learning from canned demos.

No comments:

Post a Comment