MT-Dispatch is a Perl application and plugin for Movable Type that allows Movable Type to run under FastCGI with functional background tasks and external to the webserver.


The default Movable Type installation runs a new instance of Movable Type for each request. Blogs with moderate user levels can buckle under this overhead if they get a DOS attack on their trackback or comment scripts. MT-Dispatch is a Perl application that runs a multi-process FastCGI server for Movable Type. It runs external (or internal if necessary) to your web server and provides a persistent Movable Type environment.

Unlike Movable Type’s new, native, FastCGI or mod_perl support, MT-Dispatch has no problem running background tasks. With MT-Dispatch you can have a persistent environment and avoid those annoying “rebuilding weblog” messages. MT-Dispatch also hooks into Movable Type’s Dashboard allowing you to recycle the worker processes without dropping to the command line.


Download version 2.02.

Download version 2.00.

Download version 1.5.

Download version 1.4.

Checkout the development code from my repository:

svn co svn:// mt-dispatch
cd mt-dispatch
perl Makefile.PL
make dist



  1. Synchromization of code to MTOS 4.25 and 4.261 (FastCGIMaxTime and FastCGIMaxRequests)
  2. bug fixes, including MT_PERIODIC behavior and background tasks. (Thanks, MC and FS.)
  3. File::Slurp now provided in extlibs.
  4. Light Worker threads now added. Light workers do not run periodic tasks and are more available to serve page requests.
  5. New and updated environment variables.


  1. Synchronization of code to MTOS 4.21
  2. New directory structure, extlibs, and code organization.
  3. removal of unneeded unicode support logic
  4. many bugfixes
  5. improved responsiveness to requests and tasks
  6. auto recycle on several events, like changed settings and upgrading


MTOS 4.25 has added control logic for FastCGI processes. This logic has been ported to MT-Dispatch 2.02. Use the mt-config.cgi directives ‘FastCGIMaxRequests’ and ‘FastCGIMaxTime’ instead of the ‘PERL_FCGI_MAX_REQUESTS’ environmental variable. Some defaults have also changed.

The directory structure changed in 2.00. Mt-dispatch.fcgi and are now found in the bin subdirectory. You will need to update your server config to take into account of this new layout.

You should also apply a one-line patch to your MTOS installation. See below for details.


To install extract the distribution and copy the contents to your MT directory, e.g.:

tar xvzf ~/MT-Dispatch-2.00.tar.gz
cp -R MT-Dispatch-2.00/* /usr/local/www/cgi-bin/mt/

MT 4.25 and earlier have a bug (#79933) that prevents MT-Dispatch from working properly with config.yaml files. You need to apply the one-line patch in the archive. (The patch was made against 4.21, works with similar versions.) This bug is fixed in MT 4.261.

cd /path/to/mt/
patch < plugins/MTDispatch/MT.yaml.patch

Bug Note: MT 4.261 contains bugs that may cause database connections to fail after attempting to run a background task. Background tasks should be disabled if you experience this bug.

Now rename every Movable Type app that you want the dispatcher to run, e.g.

mv mt.cgi mt.fcgi
mv mt-comments.cgi mt-comments.fcgi
mv mt-tb.cgi mt-tb.fcgi

Don’t forget to update the script directives in your mt-config.cgi file.

MT-Dispatch requires any app that it runs to conform to the standard MT::Bootstrap usage.

Lighttpd Configuration

Running mt-dispatch externally is a better way to go; however, it is easier to setup mt-dispatch to run internally. If you run Lighttpd, you can configure MT-Dispatch to run internally to your webserver like this:

server.modules += ("mod_fastcgi")

$HTTP["url"] =~ "^/URL/TO/MT/" {
    cgi.assign = ( ".cgi" => "" )
    setenv.add-environment = (
        "MT_HOME" => "/PATH/TO/MT/",
        "MT_DISPATCH_CHILDREN" => "4",
        "MT_DISPATCH_KEY" => "1776",
    fastcgi.server += ( ".fcgi" => ((
        "socket"   => "/tmp/mt-dispatch.sock",
        "bin-path" => "/PATH/TO/MT/plugins/MTDispatch/bin/mt-dispatch.fcgi",
else $HTTP["url"] =~ "^/cgi-bin" {
    cgi.assign = ( "" => "" )

See also Lighttpd Mod_FastCGI Documentation.

You can remove those last three lines if you aren’t serving MT from a normal ‘cgi-bin’ directory.

Apache Configuration

On Apache 2.x you can use mod_fcgid to run MT-Dispatch:

LoadModule fcgid_module modules/

<IfModule mod_fcgid.c>
    DefaultInitEnv MT_HOME /PATH/TO/MT/
    DefaultInitEnv MT_DISPATCH_KEY 1776
    <Directory "/PATH/TO/MT">
        AddHandler fcgid-script .fcgi
        Options ExecCGI
        allow from all
        FCGIWrapper /PATH/TO/MT/plugins/MTDispatch/bin/mt-dispatch.fcgi .fcgi

You don’t have to access MT-Dispatch as a wrapper. You can also access it using rewrite rules, e.g.

LoadModule fcgid_module modules/

<IfModule mod_fcgid.c>
    DefaultInitEnv MT_HOME /PATH/TO/MT/
    DefaultInitEnv MT_DISPATCH_KEY 1776
    RewriteEngine on
    RewriteRule ^/URL/TO/MT/(.+\.fcgi)$ /URL/TO/MT/plugins/MTDispatch/bin/mt-dispatch.fcgi/$1 [QSA,L,PT]
    <Directory "/PATH/TO/MT">
        AddHandler fcgid-script .fcgi
        Options ExecCGI
        allow from all

External Configuration

A better way to run MT-Dispatch is to spawn it external to the web server. This configuration allows the dispatcher to be stopped and started without restarting the main web server. It also makes it possible to run the dispatcher on dedicated machines. The spawn-fcgi program is the easiest way to spawn MT-Dispatch externally. Otherwise, you can use ideas from FCGI::Spawn to spawn MT-Dispatch.

MT-Dispatch comes with an rc.d script that can be used to control the dispatcher externally. It was written to work on FreeBSD, and below are instructions for setting up MT-Dispatch to work externally on FreeBSD with Lighttpd. Changes will need to be made for Linux and/or Apache. Note that this script can have different default values than mt-dispatach.fcgi.

Symlink or copy bin/mt-dispatch.fcgi to /usr/local/bin/mt-dispatch and bin/ to /usr/local/etc/rc.d/mt-dispatch, and make sure they are executable e.g.

cd /usr/local/bin
ln -s /usr/local/www/cgi-bin/mt/plugins/MTDispatch/bin/mt-dispatch.fcgi mt-dispatch
chmod +x mt-dispatch
cd /usr/local/etc/rc.d
ln -s /usr/local/www/cgi-bin/mt/plugins/MTDispatch/bin/ mt-dispatch
chmod +x mt-dispatch

Now edit /etc/rc.conf and add the following lines. (See for additional options.)


Now you can start/stop/restart the dispatcher with

/usr/local/etc/rc.d/mt-dispatch start
/usr/local/etc/rc.d/mt-dispatch stop
/usr/local/etc/rc.d/mt-dispatch restart

Finally, edit your Lighttpd configuration and add the following lines, tailoring them to your setup.

server.modules += ("mod_fastcgi")

$HTTP["url"] =~ "^/URL/TO/MT/" {
    cgi.assign = ( ".cgi" => "" )
    fastcgi.server += ( ".fcgi" => ((
        "socket"   => "/tmp/mt-dispatch.sock",
else $HTTP["url"] =~ "^/cgi-bin" {
    cgi.assign = ( "" => "" )

Restart your lighttpd server and start mt-dispatch. You are now ready to access your Movable Type scripts with FastCGI, background tasks, and external to your web server.


MT-Dispatch comes with a plugin that integrates recycling of the worker threads into the Dashboard. If you have system administrator privileges, you can access the control page via the “Tools:Dispatcher” menu.


MT-Dispatch is controlled by the following environmental variables. Many of them have default values or can be guessed.

  • MT_DISPATCH_CHILDREN: specifies the number of worker threads (default 1)
  • MT_DISPATCH_LIGHT_CHILDREN: specifies the number of workers which will not run periodic tasks (default 0)
  • MT_DISPATCH_LOG: log location (default stderr)
  • MT_DISPATCH_SLOT_DRIVER: packaged used to schedule light and heavy worker loads. (Default MT::Dispatch::Slots::IPC, uses IPC::Semaphore)
  • MT_DISPATCH_KEY: the worker scheduling key. Should be set to a unique number to ensure that IPC::Semaphores does not run out of resources.
  • MT_HOME: path to the MT installation. Usually required.
  • MT_CONFIG: path to the MT configuration file.
  • MT_URL: relative url to the MT installation.
  • MT_PERIODIC: control the handling of periodic tasks (default ‘5’). ‘0’ turns it off. Is used to specify the batch size for periodic tasks, including the publishing queue. Can also specify the “find job size” for TheSchwartz, by using a separate value separated by a comma, e.g. ‘5,10’.
  • PER5LIB: additional directories to search for libraries.


Like all persistent environments, MT-Dispatch is susceptible to memory leaks in MT or plugin code. MovableType’s “FastCGIMaxRequests” and “FastCGIMaxTime” options configures MT-Dispatch to harvest workers after a certain number of requests or time. This releases memory trapped by leaks.


Having memory Issues?

Try lowering “FastCGIMaxRequests” or “FastCGIMaxTime”.


On this blog and The Panda’s Thumb the amount of traffic and spam that we were getting was swamping our moderately powerful server. In September 2006, I began running Movable Type on Apache under FastCGI using dispatcher code by Brad Choate. However, Apache’s FastCGI implementation left much to be desired.

About a month later I migrated my server from Apache to Lighttpd, for among other things its better FastCGI support. Lighty supports two modes of FastCGI implementation. At first I ran a dispatcher similar to one I ran on Apache, which was spawned by the server itself. However, I eventually rewrote the dispatcher into one that can be spawned externally to the web server because external spawning has added benefits. I can now start, stop, restart, and update my Movable Type FastCGI instances without restarting my web server, because my dispatcher now acts as its own multi-process server that communicates via FastCGI. Running a FastCGI script external to the web server is the preferred method for running them under Lighty. (Apache is also moving this route.)

3 TrackBacks

MT4.2+FastCGI from 日々のひとひねり on January 26, 2009 8:28 PM

MovableTypeをFastCGIで動かすには、単純にApacheのhttp... Read More

少しでもMTの動作を高速化できるように、MTのFastCGI化+MT-Dispa... Read More

MT-Dispatch Configuration from MindWard 学而第一 on May 25, 2009 3:06 PM

尝试正确配制Apache2+fcgid,发现需要在每个中重新指定fcgid的配制... Read More

About this Archive

Find recent content on the main index or look in the archives to find all content.


Powered by Movable Type 4.37