| Browser detection and PHP |
| Tuesday, 18 July 2006 | |
|
You may have seen in my last blog that I’m re-writing the FF1GP website from scratch. The last few days I’ve been working on the Browser detection. Now why do I need browser detection? One of the new things that the framework is going to support is AJAX. How it does support AJAX is being worked on, but I’ve done a little bit of AJAX coding on the Rares Database for the Tech Haven Network. So I look through the PHP manual and find a little function called get_browser() It does the job I want it to, until I look a bit deeper into the function. First of all it is dependant on a ini file, whoGary Kieth at his website generates a new version every week. I got to say ? does an excellent job in keeping this file up to date. However there is a problem with this file, its 200k in size. For a small website, with low hits it’s not a major problem, but when you get lots of visitors loading your pages, you start to get a problem. If PHP is loading a 200k file and parsing it, for each page request, you could run into a resource issue with memory and CPU. Also you will have slower loading pages as well. So how do I overcome this resource problem? Quite simply, only get the data from get_browser() function once. What I do, is check in a DB table if the browser string is there. If it isn’t I call get_browser() and serialise the data it returns, and then store it in the database for future use. I also return the data from get_browser() to my script. If the data is there, I get the serialised data from the database, unserialise it and return the data to my script. |