Skip to content

Using the Coral Cache system for hits from popular sites

While it has never happened, and my site hasn’t been dugg or slashdotted I don’t want to wait to see what happens when it does (I know my server isn’t powerful enough).

One very nice solution to protect against this is to create a ‘blacklist’ of referrals, and if a user comes to the site from one of these then I redirect them off to a cache (the Coral Cache more specifically).

This can work for any linking site, all you need to do is add the main domain into the array list, so for example if you wanted to protect from the BBC linking you would add a new element of the array that contained ‘bbc.co.uk’.


// We're not from the webcache we're going to use, and we do have a referal
if (strpos($_SERVER['HTTP_USER_AGENT'], 'CoralWebPrx') === FALSE && isset($_SERVER['HTTP_REFERER']))
{
// Protect against big sites hitting and taking you down
$siteArray = array(
'digg.com',
'slashdot.org',
'del.icio.us'
);
// Check all sites
foreach($siteArray as $site)
{
if (strpos($_SERVER['HTTP_REFERER'], $site))
{
// We are being forwarded
header('Location: http://'. $_SERVER['HTTP_HOST'] .'.nyud.net:8080'. $_SERVER['REQUEST_URI']);
die();
}
}
}

The script performs a simple array lookup checking each domain in the array against the referral to your site and if one of the blacklisted ones is found it redirects to the Coral Cache and stops executing, meaning your server isn’t overly loaded by the slashdotting or digging.

Published inMisc

Be First to Comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.