02 July, 2009

Hacking away at PHP

I got involved with a geocaching TB race being held here in South Africa. The race rules were all set up by a geocacher called cincol who is a South African living in Qatar. At first I offered to keep score with him, and then looked for a way to "publish" the scores on the web.
I contacted another geocacher, who publishes cache find scores on a web site for all the South African cachers, and he was quite happy the he would host my few pages on his site.

The previous year the race contained 16 entrants, and I thought this year it would be more or less the same. To update a few static HTML pages would not be a huge task. On the day the race started we had 47 entrants, and at one point I was hoping to break the previous years 16.

This became a huge task to maintain, so I opted to PHP-efy the pages a little. And so began my first look at PHP. I have done a few financial web sites in ASP, so thought it could not be to hard.

There were times I found it very frustrating to work with PHP, as I had no intellisense, but was quite intregued in how I could address an array in PHP (key/value pair).

Another cacher (Far-Jar-Hug) pointed me to a PHP script which could extract GPS points from a KML file, and create a small signiture item for ones Travelbugs. Link:caughtatwork

This set me on enhancing the static info of the travel bugs to include the last location of each bug. I wanted to add the GPS position as well, but this has very little meaning unloss you are seeking a cache. After a little bit of a search on the net I found GeoNames, which will give you the country, province / state, and near which town it is.

As the page loaded very slowly, I set out to optomise it a little and cache the info localy on the web server, but this does require me to log in once every morning to get the new KML and location files. But hay it works for now.

As I mainly program in C# now, I found it quite interesting how another language works. Sometimes I found PHP very primative, and not very well structured, but this could be due to my inexperence in PHP, and other times quite amazing. All in all, I am enjoying the little bit of hacking I am doin in PHP.

I was also amazed that I was able to download install and run an Apache server (MicroApache), using PHP on my windows maching and the complete download was less than 2 Meg. That is impressive! So I can code, debug, fix the pages localy on my machine, and upload to the Linux server where it is hosted. One thing I battled with though is getting the configuration just right to work. I event ran it of my USB stick for a short period.

I was put in touch with someone else who is hosting a TB race in the states. I zipped up the files and sent the web site off to him. With the questions and issues he is having, I can see it should maybe rewrite it with less hardcodeing and more configuration options. But the site did not start out to be hosted multiple instances. Maybe refactor it and then put it on source forge, if there is a small demand.