08 May 2007

Moving your website? Check the ttl

Sometimes you just have to move your website.  Perhaps you were hosting a website in a subdirectory of another site and it became popular?  Perhaps you need to move to another website hosting company?  The reasons are many and varied.  There are a couple of quirks to watch out for.

Recently I had to move one of my websites that was in a framed redirect hosted in a subdirectory of another site.  I decided it was time to give it its own bandwidth allocation, space and framed forwarding had caused a few problems with retrieving URL paramaters on the _GET line - up until then I had to check the referrer constant in the _SERVER environment array.  Unfortunately it is up to the browser to fill in the referrer constant and many choose not to, or are prevented by privicy software and hence preventing a significant number of users from using the website.

So, into its own non-redirected space the website was to go!  I copied the website over to the new space and removed the framed forwarding.  But checking the databases after a few hours I noticed that while the new website was getting some hits the old website was continuing to get hits!  In fact the old site was still getting many more hits!  How can that be?

Well that is due to a server setting called TTL which means Time-To-Live.  This sets how long a server should wait before copying the new IP.  Ideally an hour is easily enough (to enable you to play around without having test settings propagated around the net), but in my case this was set to 24-hours.  You have to realise that a TTL of 24 hours doesn’t mean that it will take 24 hours to propagate settings around the net, but just that it will take 24 hours to be copied by the servers that read it.

Remember the 6 degrees of seperation theory?  (Six degrees of separation refers to the idea that if a person is one step away from each person he or she knows and two steps away from each person who is known by one of the people he or she knows, then everyone is an average of six “steps” away from each person on Earth.)  Whilst the internet doesn’t really work like that it isn’t too bad an analogy!  It can take 6 times your TTL  for your IP change to be propagated around the majority of the net.  And then people’s PC’s & routers have DNS caches too which can add another significant time factor.  In fact, in my case I was still getting hits to my old site 10 days later.

Before you start anything get your TTL changed - set it to an hour, or 10 minutes!  This may be impossible on a shared hosting server, but you can always try!

That of course raises a second problem to do with your database.  If you’re not storing any data then you this doesn’t affect your site!  But if you are storing data how exactly do you reconcile or merge two databases once your old site finally expires?

The answer is that you don’t !  Don’t put yourself in a position where you have two copies of live data - you can get away with a manual merge while your dataset is small but even if it is a small dataset you’ll still be making a real rod for your own back.  The solution is to take your website offline (or just make your data read-only if you can) for perhaps 5 minutes while you: make a backup, copy it to the new site’s database and then point the OLD site’s database configuration at the NEW site’s database, then bring your old site back online.  The idea is to configure so that BOTH the old & new website use the new site’s database simultaneously.

If you’ve also made changes to your website in the crossover make sure you go to google webmaster tools and delete the parts of the site that are no longer valid, and set your crawl rate to ‘Faster’.

comments powered by Disqus