Learning Movable Type: Comments.cgi and Server Loads


A few weeks ago I got a telephone call from my web host letting me know that "one of your Movable Type CGI scripts is using up half the resources of the server and would you please disable the script before we find it necessary to close your account?" Don't you just love news like that? Fortunately, it all got sorted out within a couple of hours; here's the scoop.

If you've had your MT blog for a while, since before version 3.2, you may have upgraded your MT installation, but didn't bother to make changes to the code in your templates. In the templates for one of the earlier versions of MT, if you use Typekey authentication, the Individual Entry Archive Template calls the comments.cgi script to invoke a javascript file that reads back to the commenter their name. Turns out that every time a page displays that includes a Typekey-authenticated comment, the CGI script will run. One of my sites is fairly high traffic, and starting some time last year I was getting over 25,000 requests to the comments.cgi script each day.

This is the line of code that can bring your server to its knees:

<script type="text/javascript" src="<MTCGIPath><MTCommentScript>?__mode=cmtr_name_js"></script>

The solution is easy. Really easy.

1 Make sure you have a version of mt-site.js on your server, in the directory of the blog whose code you are editing. If you don't, follow these instructions from the Six Apart Knowledge Base.*

2 Put the following line of code in the header section of your Individual Entry Archive Template:

<script type="text/javascript" src="<$MTBlogURL$>mt-site.js"></script>

3 Remove the following code from the comments section of your Individual Entry Archive Template:

<script type="text/javascript" src="<MTCGIPath><MTCommentScript>?__mode=cmtr_name_js"></script>

4 Save and rebuild your Individual Entry Archive.

Many thanks to Jay Allen, who suggested many months ago that the comments.cgi was invoking the javascript causing that huge amount of pings to the cgi script, and to Arvind who figured out exactly what was going wrong and then fixed it for me. (Arvind, I love you, if you were only 20 30 years older...)

*In case the 6A site is down, the instructions are the following:

1. In your weblog, on the Templates > Indexes tab, select Create New Index Template.
2. Specify Site JavaScript as the Template Name, and mt-site.js as the Output File.
3. Make sure that "Rebuild this template automatically when rebuilding index templates" is checked, and then click SAVE.
4. Click Templates in either the left sidebar or the breadcrumbs menu to return to the Templates listing.
5. Select the new Site JavaScript template you just created.
6. Select Refresh Template(s) from the More Actions dropdown menu, and click GO.

This will create a new Site JavaScript template with the default code, as well as a "backup" template which can just be deleted (since it will be empty).

After creating this new template, you'll need to rebuild it to generate the mt-site.js file in your blog path.

Make sure you spell and capitalize the name exactly as shown (i.e., JavaScript, not Javascript).


Posted by Elise Bauer on May 22, 2006 8:05 PM to Learning Movable Type http://www.learningmovabletype.com/