The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Apache::Throttle - Apache/Perl module for speed-based content negotiation


    PerlTransHandler   Apache::Throttle

    # See the Apache::Throttle::Log manpage for options...
    PerlFixUpHandler   Apache::Throttle::Log


Apache::Throttle is made up of two separate modules.

Apache::Throttle is responsible for negotiating the content of certain requests based on the speed of the connection. It does this by checking each request to see if it passes the following criteria:

  • it is a directory,

  • it does not end in a /,

  • and it contains a file named .throttle.

If the request passes, Apache::Throttle will open the .throttle file and read a number from it. This is the time (in seconds) that the requested file should take to send, ideally. It then takes the sizes of each of the files in the directory (ignoring any that start with a period) and calculates the speed required to send the file to the client in under the specified number of seconds. Finally, it predicts the speed of the current connection and maps the request to point to the largest file that can still be sent in the ideal time.

This implementation allows you to create a virtual copy of a file simply by dropping the different versions of the file into a directory in your HTML tree with same name that you want the file to have. These files can be named anything you want, although they should end in the same extension for MIME-type mapping to work properly. A script, throttleimg, is provided which automatically sets up this directory structure from an existing GIF or JPEG image.

Apache::Throttle::Log is responsible for measuring the speed that other requests are transmitted at and calculating the average transmittion speed for each connection. This information is used by Apache::Throttle by default, but it can also be accessed by other modules. See Apache::Throttle::Log for more information.


This option can be set with the PerlSetVar operative in one of your Apache configuration files.


Prints extra debugging information to the error log.


Sets the subroutine called to predict a connection's speed. This defaults to Apache::Throttle::Log::predict_speed. If the package that the specified subroutine is in can be determined, it will be required automatically.


This doesn't only work with images. It can also be used to send different quality audio files, animations, etc. You can even use a directory named index.html if you want, with two different HTML pages for high- and low-bandwidth users. The possibilities are endless. If you think you've used this is a way no one has though of before, mail me. I'd love to hear about it.


Don Schwarz <>


Apache::Throttle::Log, throttleimg, mod_perl


Copyright (c) 1998 Don Schwarz. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.