Delete all .svn metadata on a Windows system

This is just one of those solutions that you come across and you just want to save for later because you know you'll need it again at some point in the future.


So you have a project in Windows which was stored in an svn repository and still has all the .svn metadata in every folder within. You want to clean this up and get rid of all the meta, perhaps to version control in a different system, or upload to FTP or whatever.

Easiest way I've found is to copy-paste the code below in notepad, save it as delete_svn.reg, double-click the .reg file to add the code to your registry, then simply go to Windows Explorer, right-click your top-level folder, and select Delete SVN Folders from the context menu. You'll see a cmd prompt pop-up for about half a second and you're done! Now why is it that trying to do a search in Explorer, then trying to delete the files via the Explorer UI takes about 100 times longer...

Anyway, here's the code:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN]
@="Delete SVN Folders"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN\command]
@="cmd.exe /c \"TITLE Removing SVN Folders in %1 && COLOR 9A && FOR /r \"%1\" %%f IN (.svn _svn) DO RD /s /q \"%%f\" \""
Oh, and I didn't come up with this. I pinched it from here, so full credit goes to the original author.

Laptop with two external screens

I use my laptop as my primary work/study/home PC. The laptop itself has a fairly small 13.3" screen but compensates with a high resolution of 1440x900. At work I also have a 17" Dell desktop LCD with a native res of 1280x1024. I've been using this as an external second monitor for a full year now. Doing this is simple enough, just plug in the VGA cable into the laptop's VGA port, hit WinKey+X in Windows 7, choose connect display and select extended desktop.


Extending the desktop on two screens allows you to move application windows between the screens freely, so you could have say Firefox open and maximized on the external screen and Microsoft Word open and maximized on the laptop screen. The productivity gains from doing this are quite significant. Instead of having to Alt+Tab between applications you can just move your gaze from left to right. This doesn't sound like much, after-all hitting Alt+Tab only takes about half a second. Switching gaze however is far less intrusive on your though process and allows you to retain focus much better.

So if having two screens is good, three must be even better, right? Only problem with connecting a second external screen is that my laptop (and most laptops ever manufactured) only have one VGA port. Fortunately though, all is not lost. Here's where the Skymaster USB to VGA Adapter comes in, or more accurately USB to USVGA as it supports a maximum resolution of 1600x1200. The device is basically a small external video-card that connects to your PC via USB and has a VGA port attached to it (or DVI/HDMI via an additional bundled adapter).

I had my doubts as to how well this would work, especially after reading some old articles about similar products where the image was choppy and low res. I bought it anyway though, and glad I did! Setup was extremely easy. Just take it out of the box, throw the driver CD that comes with it in the bin, connect it to the laptop via the supplied USB cable, let Windows 7 automatically detect the device and download and install the needed drivers, connect the screen, hit WinKey+X again, choose to connect display, select extend desktop and you're done!

You may also want to right-click the desktop and go to screen resolution, then make sure the two external screens are both running at their native res, and also drag the screens to position them in the right positions relative to their real physical locations (Windows got this wrong by default (it's impossible for it to detect) and my mouse would move through the left edge of my laptop screen and appear on my right monitor).

Performance-wise, the USB to VGA adapter is good but not perfect. When moving the mouse pointer there's a slight microsecond lag at times, but it's barely noticeable. Otherwise image quality is as good as the other external screen, running at 1280x1024. YouTube videos seem to play without any noticeable lag, although I'm not sure how well a full screen DVD quality video or a game would play. Having said that though, my laptop has a 1.2GHz ULV CPU, so maybe this would work better on a more powerful machine (I notice more cursor lag when my laptop is busy doing other stuff so it's probably using some sort of software emulation).

As for productivity, it's the bees knees! I can put my Chrome browser on the left screen, my Netbeans PHP development environment on my laptop screen, and my Firefox browser pointing to my development site on the right screen. This way I can quickly Google some APIs and code snippets, copy-paste over to my development environment, hit Ctrl+S to save and look over to the right where I refresh my development page and see the effects immediately. Sweet!

Minimalistic Ubuntu Virtual Machine with VirtualBox on Win 7

I've been meaning to create a minimalistic Linux Virtual Machine that I can clone and adapt to particular needs for a while now and today I finally got around to doing it:
  • Download VirtualBox from here (free for personal use).
  • Download an Ubuntu Minimal CD Instal iso from here (I used 9.10 x32).
  • Open VirtualBox and create a New virtual machine by following the prompts (I gave mine 384MB RAM and a 7GB dynamic disk (this is the MAX size)).
  • Once the VM is created, click on settings and tweak whatever you like. Select to mount your Ubuntu ISO in the storage area.
  • Start the VM and at the Ubuntu installer boot: prompt type cli and press enter.
  • Follow the installer wizard selecting appropriate values (I selected to install on entire HD with no LVM).
  • Once the installation is complete, unmount the ISO and restart the VM.
  • Once at the Ubuntu terminal:
  • >>sudo gedit /etc/apt/apt.conf
  • ----ACQUIRE {http::proxy "http://username:password@proxy:port/"}
  • >>sudo aptitude install xorg ---(the graphical core)
  • >>sudo aptitude install xfce4 ---(minimalistic window manager)
  • >>sudo aptitude install gdm ---(graphical login manager)
  • >>startx ---(load the window manager)
  • At this point you may want to shutdown the machine and create a clean snapshot.
  • Fire the machine back up and install remaining packages you're interested in, e.g:
  • >>sudo aptitude install firefox
The snapshots allow you to change between different states of the machine so you can have multiple Firefox versions in different snapshots that all branch from the clean install.

And for anyone thinking of using the Windows 7 Virtual PC VM instead, not such a good idea. I tried installing Ubuntu 9.10 minimal on my Win 7 Pro x64 laptop within Virtual PC. Installation completed successfully but after a restart I was greeted by segfaults. Turns out this is a very common problem that can be worked around by assigning more ram to the VM image, but even then you get no guarantees of things randomly failing.

Windows 7 Hard Disk Thrashing

I recently noticed my Windows 7 HTPC has been spending a lot of time doing 'something' with the hard drive, but I had no idea what. That is, the hard disk activity light would keep flickering constantly and you could hear the disk churning away. This also resulted in choppy Live TV playback as the HD needs to be used to record & play simultaneously.

I tried disabling Microsoft Security Essentials, turned off the disk defrag service and SuperFetch. Restarted several times for good measure as well but problem persisted. I then opened up the Resource Monitor and had a close look at the Disk tab. This shows a list of processes and their real-time hard disk read and write data rates.

Sorting by read speed I noticed many instances of wmpnetwk.exe. The disk activity pane showed that this program was opening up a lot of my mp3 music files. A quick Google search revealed that this is the Windows Media Player Network Sharing Service. This is used to stream music and videos to other devices in your house like an XBox or PS3, but I never explicitly turned this on and I don't use the functionality.

Disabling the service resulted in a significant reduction of HD activity. The two processes left that were reading and writing to the disk were ehrecvr.exe and ehshell.exe. ehrecvr is the Live TV component of Windows Media Center and ehshell provides core WMC functionality. If ehshell is creating too much excess activity, try restarting WMC or check to see if WMC is scanning for new libraries or trying to perform its optimization, etc.

If none of the above apply to you, just try to use the Resource Monitor to identify the processes and services that are hurting your HD. Identify what files they're accessing. Google to see what they do if not sure and shut them down if not needed.

rm - too many arguments

I was trying to delete about 55,000 files in an Ubuntu directory the other day. Something along the lines of:

rm -f *


This failed with a "too many arguments" error. The root-cause of this seems to be a little involved, but the simple one-line workaround is:

find ./ -name '*' -print0 | xargs -0 rm

Australia's Internet Filtering

Australian Labor Senator Stephen Conroy (Minister for Broadband, Communications and the Digital Economy and Deputy Leader of the Government in the Senate) is the champion of a new policy to implement ISP level internet filtering in Australia.


The way this works is the government will compile a list of URLs in secret that they think us Aussies should be shielded/protected from and will distribute this blacklist to all ISPs. ISPs will then be required by law to block access to any URLs on this hidden list.

A similar filtering system is used in other countries such as China, Cuba, North Korea, and Iran. If this policy gets approved, we'll soon be joining the ranks with the above. The government will get to control what we can and cannot access.

The publicized intention of the filter is to block people from highly malicious websites, but that's just the cover story to gain the parent vote and conservative older generations vote. Those that actually have a clue about how the internet works know that this is total rubbish. These things are all done underground via peer-to-peer applications and encrypted distribution networks. Blocking URLs will have no impact on truly malicious content. Instead, the government will be able to slowly start banning access to sites that they think make us unproductive, or are bad for our local economy, or bad for spreading radical views, etc.

China for example blocks (or have blocked) access to sites such as Youtube, FaceBook, Twitter, Google Web Albums, Google Docs, and pretty much any other social networking site. The Australian filter will obviously not start out by blocking these, but how far down the track do you think it'll take before we slowly get there? If people are willing to step back and accept this filter, the government will slowly push the boundaries further and further as it sees fit to further its own agenda.

If you think this is a bad idea, then you need to take action. See http://stephen-conroy.com/ for a list of email addresses you can contact to make yourself heard, or head on over to this Whirlpool thread for a very active discussion on the matter.

Google Nexus One Released

The highly hyped Google Nexus One phone has finally been revealed today and is now available for purchase directly from http://google.com/phone. That is, if you live in the US, UK, Hong Kong or Singapore. The rest of the world misses out for the time being as Google will not ship to other regions (although some imports are sure to trickle through).


Google has stated that they're looking to expand this to Verizon in the US (it's all about the US) and Vodafone in UK/Europe in the near future. No word as to other regions just yet, but it appears what Google is trying to do is enhance the public presence of Android and increase general public awareness.

That is, Google is offering to sell Android phones directly through their web-pages where customers can choose one of many Android models from different manufacturers and one of many different carriers available in their region, or outright unlocked. The Nexus One (HTC) will be just one of many. Likewise, T-Mobile, Verizon and Vodafone will be just the first of many carriers that will be directly linked.

It would also make sense if Google took this opportunity to ensure some sort of conformity for all phones sold through this distribution model. That is, all running the same version of Android with the same interface and receiving updates simultaneously. This consistency is much needed if the Android Market Place App Store equivalent is to have any chance of explosive growth. At present, it's impossible for developers to predict what Android version people are running, what hardware is available, how much memory, how much graphic processing power, screen resolution, size and ratio, keyboard or other input methods, etc.

As for the Nexus One itself, full specs are available here. Reviews so far are good but not great. There's nothing particularly revolutionary about the phone or software, just a marginal hardware upgrade over the Droid and Milestone. Other phones will be available in the coming months that match and surpass it's specs including the HTC Bravo and Sony Ericsson X10.

If you're lucky enough to be in one of the regions that it's available in then it's a good outright buy. But if you have no choice but to import via other channels, then it's probably best to wait a little longer to see how this new distribution model develops. Although, knowing a little about how Australian telecos work I wouldn't hold out for a carrier plan any time soon. Best us Aussies can hope for is that Google decides to ship the phones to us unlocked for full outright price.

Microsoft Office 2010 Free Beta

The Microsoft Office 2010 Professional FREE beta is now publicly available for everyone to download. Whilst trying to install this I got an error message stating that "An Office 2003 installation on your computer is corrupted and setup cannot continue. Remove or repair Office 2003 product and re-run setup." This was on my Windows 7 Pro x64 laptop.


I did indeed have Office 2003 installed but I had removed it via the control panel Add/Remove programs before running the downloaded Office 2010 beta. I then tried the Microsoft Office Removal Wizard utility which deleted a whole bunch of other files and assured me no Office 2003 remnants were left but the error persisted (be careful with this tool as it will delete everything in your c:/temp or any-other-drive/temp folder, Office related or not).

Turns out the cause was Visio 2003 which is also part of the Office lineup but is installed and removed as a separate product. After uninstalling Visio 2003 the Office 2010 installer worked like a charm, even though again Visio 2010 has to be downloaded and installed separately (the beta is available here).

PS3 PSN DNS Error 80710102

I tried logging in to the PlayStation Network via my PS3 this morning to check what's new but was presented with Error 80710102. The error message mentioned that This is a DNS error. I am connected via TPG ADSL2+ and a wireless router. Other websites seemed to work normally on my laptop and HTPC.


DNS is short for Domain Name System, i.e. the system used to translate friendly URL names such as www.google.com into numeric addresses such as 66.102.11.104 that are actually understood by the web (paste 66.102.11.104 into your browser address bar and it will take you straight to Google, bypassing the DNS service as no address lookup is needed). The reason we use friendly links is because they're easier to remember and also because the numeric addresses can freely change whilst the friendly names stay the same (i.e. www.google.com is unlikely to ever be renamed but 66.102.11.104 can change at any time).

A lot more can be said about DNS, but basically this error code is saying that the PlayStation 3 can't translate the PSN friendly name into an IP address. Each ISP typically manage their own DNS sub-system and in this case it seems that TPG either lost the entry for the PSN or the TPG DNS is experiencing problems (possibly due to a virus outbreak, caching issues, congestion, etc.).

The simplest solution is thus to use a different DNS such as the new Google Public DNS. To do this, just go to the PS3 Network Connection Settings and choose to manually configure the details. You'll need to assign the PS3 a static IP, the subnet should be automatically detected based on IP, and you'll also have two DNS entries for primary and secondary. Here you can enter the Google IPs 8.8.8.8 and 8.8.4.4. Run a connection test once done to make sure you have all the settings correct and you should be good to go!

The Google Public DNS is a good way to troubleshoot many connection problems, such as when a website doesn't load on your PC but others work. I sometimes can't access my online banking website from my TPG connection due to issues with their DNS. Switching to Google works immediately.

Blogger anonymous comment word verification cropped

There seems to be a bug in the default Blogger templates that manifests only in some blogs with inline commenting enabled when users try to post comments as anonymous guests. The inline word-verification panel that appears is cropped with no way to scroll down to the textfield to enter the word or to the submit button.



The solution to fix this is simple. Go to the admin console, and navigate to Layout/Edit HTML. Check the tickbox to Expand Widget Templates and search for:

<iframe allowtransparency='true' class='blogger-iframe-colorize' frameborder='0' height='275' id='comment-editor' scrolling='no' src='' width='100%'/>

Change the height property from 275 to 475 and you should be sweet! :-)

The Nexus One Google Phone Blomb

If you keep up to date with any IT/Sci/Tech news feeds or blogs then you've probably already read all about the Nexus One, Google's supposedly miracle phone that will make everyone forget the iPhone ever existed and change the world as we know it.


This all started some time during the weekend when some Google employees started twittering about a new development phone they've been handed. A few blogs pick this up and start making wild speculations that Google is entering the hardware market and selling their own phone directly thus making this the official Google Phone that will put an end to all other Android devices and be the new king of the hill.

This gets picked up by other IT/tech news sites and exponentially spreads throughout the blogosphere. The information is rehashed and remixed with further opinions and speculations thrown in, morphing and expanding in grandeur and authority as it spreads. I call this the blomb, i.e. a blogosphere-bomb.

A few realists however have tried to put this back into perspective. Google has previously released two other developer phones, the HTC G1 and HTC My Touch. Both can be bought by anyone who signs up as a Google developer for a once off cost of $25. These two phones are also available through carrier plans and come with a 'with Google' branding on the casing. This new Nexus One is most likely going to follow suite, i.e. it's just a new HTC phone running the latest Android for developers to play with. Anyone can become a Google developer and buy it. And the rest of the world will soon be able to buy a variation through carriers.

Needless to say, there's also the HTC Bravo coming out 2nd quarter next year which is almost identical to the Nexus One in every way, plus a whole bunch of other HTC Android phones coming later during the year. So why would Google all of a sudden decide to publicly release and back the Nexus One as the one and only TRUE Google Phone and alienate all other Android manufacturers, including their partner HTC who has numerous models in the pipeline? It makes very little sense, yet many choose to ignore these details.

The whole Nexus One blomb also has a strong American tint to it. The US market is controller entirely by carriers where almost all phones are purchased and subsidized through long contracts. Also the carriers use different transmission standards making switching from one network to another incompatible. The idea of an unlocked, outright phone that can be used on any network seems a little unusual and revolutionary to them, whereas in other parts of the world this is quite normal. In Australia for example, you can buy an unlocked tri-band phone that supports all the major carriers. Just pop-in a pre-paid SIM you buy from a petrol station and away you go!

Don't fall for the hype and gossip. People like to make wild predictions but at the end of the day this is just another Android phone. Nothing to see here, move along.

ThinkPad x300 and the infamous 1802

As I've posted numerous times, my Lenovo x300 regularly freezes due to some unknown reason. It does this regardless of operating system (I've tried Ubuntu/XP/Vista/W7), happens more frequently on battery power, and the only way to bring it back is via a cold shutdown/reboot.


There's a specific post on the Lenovo support forums about others experiencing the same problem (update: also this and this). No official response from Lenovo yet. Some have suggested that it could be caused by a faulty WiFi adapter though and that replacing it fixes the problem.

My X300 (type 6477) comes factory equipped with an Intel 4965 802.11 a/b/g/n PCIe Mini Card. The process of replacing this is pretty easy and is documented here. So off I go to my local PC Yum Cha shop and buy a cheap 4965 replacement.

I go home, pop out the battery, pop out the old card, in with the new, screw everything back in, turn it on and...

1802: Unauthorized network card is plugged in
Power off and remove the miniPCI network card.

Ah, crap! I remembered reading about this before in regards with the 3G expansion cards but didn't think it would apply to other components as well. I guess I was wrong. Basically all Lenovo laptops have wireless card white-lists hard-coded in the BIOS. If you try to plug in a card that doesn't match certain serial/manufacturing IDs, then you get the infamous 1802.

Infamous because there are whole sites and forums dedicated to workarounds for this. Just do a Google search for 'no-1802 patch' to see what I mean. There are a number of apparent solutions, ranging from running a DOS patch to flip a bit in the BIOS, to decompiling, hacking and rebuilding your own BIOS, or taping up pin-20 of the card and inserting it in the 3G slot.

Now I haven't tried any of these hacks and don't intend to really. Hacking the BIOS could permanently brick your machine. Besides, mine's still under warranty as well so I'd be better off finding some time to send it in for diagnosis and repair.

It's very disappointing to find Lenovo doing this. I think it might be due to some FCC wireless transmission device approval laws in the US, but it sucks that it effects everyone world-wide, especially when you get bitten by it completely unexpectedly.

If you still want to replace the wireless card, you need to do it the Lenovo way. That is, do a parts lookup for your specific model, get the FRU part number, go to the Lenovo part store for your region, punch in the FRU, take out your credit-card and hand over all your cash.

For the record, I bought the 4965 locally for $48. The Lenovo sanctioned equivalent (FRU 42T0865) costs $151.80, over 3 times more expensive! And if you think that's bad...check out how much they charge for the internal 3G WWAN cards.

Import Google Contacts to Nokia PC Suite

You would be forgiven to think that importing contacts from your Google address book into Nokia PC Suite would be an easy and straight forward task. Google Contacts has 3 export options: a proprietary Google CSV, a standard Outlook CSV and the vCard format. Likewise Nokia PC Suite allows importing Outlook CSV and vCard formats. Having recently tried both methods though, neither worked.

The Outlook CSV format failed with some error message and informed me that no contacts were imported. The error message gave no clue as to why. The vCard format on the other hand would import only a single contact.

After a little bit of digging around I found that the vCard .vcf file exported by Google Contacts is a composition of all your contacts, but Nokia PC Suite expects only one contact per .vcf file. A quick Google search reveled just the tool for this, vCardSplit. Using it is pretty simple: just dump your contacts.vcf file into a folder, say C:\temp, dump the vCardSplit.exe into the same folder, open a command prompt and type vCardSplit.exe contacts.vcf.


Back in Nokia PC Suite, go to Contacts and select import, then hold the shift-key and multiple-select all the .vcf contact files (Ctrl+A doesn't work because Nokia decided to snazzy up their interface and code their own file-select dialog). Click import and you should get all your contacts.

However, in my case I noticed none of the phone numbers showed up! Names and emails were there, but no numbers. The solution to this is to open up the contacts.vcf file you exported from Google and replace all instances of "VERSION=3.0" with "VERSION=2.1" and also replace all instances of "TYPE=" with "" (i.e. nothing). Then run the split tool again and import the contacts into Nokia PC Suite again. This time all info should come through (haven't done extensive checking, but all numbers and emails appear to be there, not sure about groups, titles and other details).

Consolidating Mobile Contacts and Calendar through Google Sync

Most people know about Google's Calendar and Contacts services (contacts is available through the GMail or Google Mail interface). I personally have Google Apps installed for my domain and use Google Mail to consolidate 4 or 5 email accounts. Likewise I use Google Calendar to jot down meetings, events and todo's, and I started using Google Contacts to store everyone's emails, phone numbers, addresses, etc.


This is all well and good when you're in front of your computer, but it'd be even better to have full access to all this information from your mobile phone. Now if you have a modern smartphone like an iPhone or Android, you can just fire up a browser and connect to your Google account via 3G. Even better though, it's possible to sync your native phone contact list and calendar to your Google account for seamless integration via Google Sync.

Google Sync is available for the iPhone, Android, Windows Mobile and Symbian. I was surprised that I could get this service running on my old Nokia N73. I spend a Saturday morning going through my Google Contacts and putting in all the phone numbers from my phone. I then signed up for a cheap data-pack, downloaded and installed Mail for Exchange for S60 via Google's instructions, created a profile linking to my Google Apps account and off I went!

The Mail for Exchange program is simply an ActiveSync client for the S60 platform (I hear this can be done on an S40 as well, such as the Nokia 6700 Classic, but haven't personally tested yet). You set up a profile listing the sync schedule (manual or every 15 minutes to every 4 hours) and pick what you want synchronized: contacts, calendar, email, tasks.

At first I tried by having all 4 synchronized, but Mail for Exchange threw an error. I read up on some Google blog that people have been experiencing this problem with tasks. So I edited my profile to remove tasks and email and the contact/calendar sync completed successfully (I don't want email on my N73 for the time being)!

I configured Mail for Exchange to delete all my existing phone contacts and calendar entries and have these replaced with the Google entries and set the schedule to 4 hours. I now have a complete list of contacts that I can manage through any web-browser, and I have all my calendar events appearing on my ancient phone with today's tasks right on the front screen. And best of all, I don't need to worry about backing up contacts from my phone memory to SIM to carrier network.

Another great feature is that Google Contacts allows you to save people's birthdays in the profile and this can be integrated with your Google Calendar (go to Other Calendars/Add/Browse Interesting Calendars/More/Contact's birthdays and events).

All in all this works great and I'm happy with the consolidation. There's only one problem (besides my ancient N73 with tiny screen and T9 keypad that severely limits calendar interaction or anything to do with emailing, etc). Google Contacts works by automatically saving into your All Contact list any email address to which you send an outbound email to. This is pretty annoying as your contact list can get cluttered by nameless emails to all sorts of weird places. It would be great if you could disable this feature, but as described here, you can't :-(

The only solution is to periodically go through your contacts and clean out any junk. The easiest way to do this is if you assign all the real contacts to groups, then do a search for an empty space ' '. This will show you contacts in a My Contacts group and contacts in an Other Contacts group. The latter are all the automatically added contacts so you can delete them all in one go. Far from ideal, but the only workable solution for the time being.

If you'd like to be able to disable the automatic adding of contacts, leave a message here.


UPDATE: Forget what I said above. While it's true that you can't stop Google from automatically storing all outbound email addresses to your contact list, this isn't a problem when synching with a phone. The reason is, automatically added contacts will not appear in My Contacts until you manually add them to a group yourself. And Google Sync will only synchronize contacts from the My Contacts group - perfect!

Simple Service Layer PHP Caching

There are a lot of plugin caching systems out there but the correct caching mechanism is often specific to each individual application. This is especially true in Ajax-like web applications where data can be highly dynamic. Sometimes it doesn't make sense to deploy a cache to your entire application, especially if your data is dynamic to the point where the overhead from cache misses could actually slow down overall throughput.


Maybe you only have one service that processes a deep hierarchical data structure. This usually involves a lot of recursion and iteration and possibly a lot of database queries. Performance for this type of services is generally n^2 and while you may not notice any significant lag with small structures, once you start exceeding the thousands of nested elements mark, things start to bog down exponentially.

The simple solution for this is to implement a service-specific cache. To do this you need two things:
  1. You must have some way of caching the service results.
  2. You must have some mechanism for invalidating the cached results when data changes.
Turns out that caching the results is very simple. Consider the following function:

public function varToFile($filename, $var) {
$filename = $_SERVER['DOCUMENT_ROOT'] . '/files/cache/' . $filename;
$data = gzcompress(serialize($var),9);
$file = fopen ($filename, "w");
fwrite($file, $data);
fclose ($file);
return $res;
}

This function will basically store a PHP variable into a file using the PHP serialize function and compression to make the files smaller. The variable could be a very deeply nested associative array containing your hierarchical data structure for example. Reading the variable back out is equally easy:
public function varFromFile($filename) {
$filename = $_SERVER['DOCUMENT_ROOT'] . '/files/cache/' . $filename;
if(file_exists($filename)) {
$data = unserialize(gzuncompress(file_get_contents($filename)));
if($data) return $data;
else return false;
} else return false;
}
All we need to do is pass in the same filename as we used to store the variable and we'll get the PHP array back. So then the only trick left is to assign unique filenames and have a way of associating these with service parameters. One way to achieve this is to use MD5.

So for example, if I want to build a hierarchical data structure from 5000 database records, I run a query to retrieve all 5000 records in an array, serialize this array to a PHP string, then take an MD5 hash of the string and use this as my cache filename. If any of the 5000 records is changed in any way, the MD5 hash should be different so I can use this as my cache hit/miss mechanism.

A simple (pseudo) example would be as follows:
$records = queryDb($query); //array of say 5000 records
$filename = md5(serialize($records)); //generate the hash key
$data = varFromFile($filename); //try to get the data from cache
if($data !== false) return data; //cache hit
else {
//start the recursive algorithm to parse records
varToFile($filename, $data); //store data in cache
}

This worked quite well in my case and reduced the loading times for my service from 40+ seconds to under 2 seconds for a cache hit. The only problem is that the cached entries are not automatically cleaned up in any way. An external script or cron task could be used to clean old entries. Also, the cache miss requests would still take 40+ seconds. If this is an issue, you could pre-generate the cache in the background whenever the data is modified, rather then when it's first accessed.