I have recently monitored a client website in Drupal 7. It was spammed by commenting with spam links. Although I deleted about 600M of spam comments, all of them have been crawled and indexed by search engine bots. At the result, there are quite traffic coming to this site looking for non existing content.

At a peak time, the VPS RAM has been used upto its limit of 2 Gigabyte. The website became very slow. Apparently, responding to those removed spamming content (404 - Page not found) has eaten up alot of the server resource. So I need to find a solution to minimize memory usage for those useless requests.

The problem is, Drupal has expensive 404 errors. When serving a 404 page, Drupal stills do a full "bootstrap", loading all modules, settings, querying database etc ... On an average Drupal site, it may consume 60-100MB just for a 404 request. If a gif file is missing, plus a CSS file is not found, that makes up two 404 requests, eating up 180M of RAM. It is too much, especially in a busy traffic website.

It is the time when Fast 404 becomes extremely useful.

Drupal Fast 404 error

Fast 404 takes charge of handling 404 errors from Drupal, serving less than 1MB of memory for each request. It can deliver super fast 404 error messages for both missing files and bad paths. In my situation, it is a savior. Now I can quickly say "NO" to useless requests to spend time for my valued customers.

Fast 404 installation

Step 1: Download the Fast 404 module and upload to /sites/all/modules.

Step 2: If you want to check for bad files only, just enable the module. That's done.

Step 3: If you want more advanced features like Drupal path checking or custom 404 HTML file, please copy the script on the bottom of README.txt file and paste to /sites/default/settings.php

For me, I really want to turn on the fast invalid path checking, so I change this setting from FALSE to TRUE

$conf['fast_404_path_check'] = TRUE;

and remove the comment of this line

fast_404_path_check();

Now, people who browse my site for a bad path will receive a simple error message like this. Simple and quick. At the result, the server memory usage dropped to 1.5 GB immediately. That's 25% of saving.

A Fast 404 error

Custom 404 HTML page

In case you want to a more decorated 404 theme, you may have a look for some templates on Design Modo.

You can download a free custom 404 HTML template and change to yours. It is more beautiful and still quicker than default Drupal bootstrap.

Custom 404 error template

Upload the new 404 HTML file to your web root directory and uncomment and change this line on the settings.php

#$conf['fast_404_HTML_error_page'] = './your_page.html';

Hope you enjoy it! Please subscribe to our newsletter, more interesting posts will be sent to you periodically.

By Thanh Le

 

Subscribe to our mailing list

* indicates required