Dedicated server needed?
Unless we have dedicated servers, many of us will have disk space usage restrictions placed on us by our hosts.
Even if we are managing space on a dedicated server, we still want to ensure that we do not run out of space without warning.
But that was the problem I was facing with one of my hosts .. over the course of a couple of days I received email alerts that my sites were taking me over the disk space limits; even after I had cleared down 300-400Mb and being within my limits, I was over again next day.
What was going on?
Did I now need to contemplate buying my own dedicated server with my own full complement of disk space or moving sites to an ‘unlimited host’ - maybe to Servage (ad on this page).
I discovered the problem …. the Affiliate Window ShopWindow product which I set up on a demo domain and featured in an earlier blog entry was being visited loads via Googlebot, and that invoked the disk caching built in to ShopWindow. Now I never saw anything documented about this, nor have I seen anything written by Affiliate Window regarding clearing it down automatically when the cache had expired. ShopWindow was using up 800Mb when the scripts themselves were only a couple of Mb large, invoking API calls to ShopWindow to fetch back the product details. (I still have that demo site up at http://www.webstorelinks.co.uk)
Now that I knew and understood the problem, it gave me an additional option …. to create a mechanism to clear down the cache on a regular basis. Obviously, I don’t want to be doing this by hand. A quick trawl around the Internet revealed that someone had already written such a script.
Save the following code as a php file somewhere in the domain that you have a folder that needs emptying periodically.
// Start of php - insert the usual < ? php open (Wordpress doesn't like displaying here)
// Settings
$cachedir = '../wwwroot/cache/'; // Directory to cache files in (keep outside web root)if ($handle = @opendir($cachedir)) {
while (false !== ($file = @readdir($handle))) {
if ($file != '.' and $file != '..') {
echo $file . ' deleted.
‘;
@unlink($cachedir . ‘/’ . $file);
}
}
@closedir($handle);
echo ‘No more files to delete - job finished
‘;
}?>
and give it any name you like xxxx.php. Remember to modify the cachedir parameter and path.
You can now run this by calling it within your web browser (if you have enabled php on your domain). The browser will show all the files that are deleted. This is useful for diagnostic purposes to make sure that it has actually deleted files. Once happy, you may choose to delete (or comment out) the ‘echo $file . ‘ deleted.<br />’;’ line.
After that, a simple task to create a cron job to visit the cache clearing script on my desired frequency.
This script will purge all files (whatever suffix) from the stated folder and can therefore be used with any other script that creates temporary data in a folder.
Take Affilistore for example. In v2.01, it now has caching enabled and also has an admin option to clear cache (very similar to the above script). Unfortunately that Affilistore script requires admin login to access it meaning that cache clearing needs to be done manually and is therefore unsuitable for a cron job. Drop this script into your site, modify the cachedir path, set up a cron job and your cachedir will be kept under control automatically.
Now I don’t mind Google and other search engines visiting .. I am managing the disk usage better now and thoughts of needing a dedicated server have been removed (for now).
Your quick comments RSS Feed