Traffic Jam: Block unwanted bots based on access speed

Recommend this page to a friend!
  Info   View files Example   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 79%Total: 271 All time: 7,616 This week: 194Up
Version License PHP version Categories
traffic-jam 0.1GNU General Publi...5HTTP, PHP 5, Security
Description Author

This class can be used to block unwanted bots based on access speed.

It keeps track of the history of accesses of bots based on their IP address. The accesses information is stored in a history file named based on the IP address.

If the bot accesses more than a given number per second, it will be blocked for a given period of time.

The class can be configured with a whitelist to allow accesses of given user agents that will not be throttled.

Innovation Award
PHP Programming Innovation award nominee
January 2016
Number 2

Prize: One downloadable copy of PhpED Professional
Sometimes sites are abused by bots that crawl them and extract their content.

Since bot scripts often send too many requests to the site servers, that may cause server overload. The site owner may also not be happy with the possibility that other sites that may be stealing their content.

This class may help fighting this kind of abuse by keeping track of the frequency of the accesses performed by bots. It can be used to block bots that are sending requests at a frequency above an acceptable limit.

Manuel Lemos
Picture of Dave Smith
  Performance   Level  
Name: Dave Smith is available for providing paid consulting. Contact Dave Smith .
Classes: 51 packages by
Country: United States United States
Age: 56
All time rank: 678 in United States United States
Week rank: 14 Up1 in United States United States Up
Innovation award
Innovation award
Nominee: 32x

Winner: 7x

Class: trafficjam
Version: 0.1 bets 10/14/2015

Copyright 2015 Wagon Trader, All Rights Reserved


This class will block unwanted bots and traffic based on speed the page is being accessed.

Configure whitelist of bots allowed which will not be throttled.
Specify length of time an ip will be blocked
Provide friendly notifications in the event a human gets blocked


trafficjam.class.php - Main class

example.php - Simple application example

jam_100.php - Display notification for access violation

jam_200.php - Display notification for unwanted bot

/history - folder to hold ip history files


Upload files to a web accessible location on your server (eg. public_html)


/history folder needs read and write access (666) or (777) on linux servers

You can change the following settings in the class to meet your specific needs...

$humanSpeed - Number of accesses per second a human would access the site. The lower the number, the more
    likely the ip will be jammed.

$jamTime - Time in seconds that an ip will be jammed.

$fileFolder - Name of folder that holds history data. For security purposes, you can change the folder name
    and set this value to the correct folder.

$dataDelim - delimiter used in history files. A complex delimiter avoids the need to manage commas, tabs, etc...

$fileExt = extension history file to use. tjm is the default, so files will be named [ip_number].tjm


Refer to example.php file for usage example.

Refer to trafficjam.class.php file for instructions on using methods


0.1 beta

Initial beta release
  Files folder image Files  
File Role Description
Files folder imagehistory (1 file)
Accessible without login Plain text file example.php Example Example Usage
Accessible without login Plain text file jam_100.php Example Jammed display
Accessible without login Plain text file jam_200.php Example Jammed display
Accessible without login Plain text file license.txt Lic. License
Accessible without login Plain text file manual.txt Doc. Documentation
Plain text file trafficjam.class.php Class Main Class

  Files folder image Files  /  history  
File Role Description
  Accessible without login Plain text file index.php Aux. Folder access holder

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:7,616
This week:194Up
User Ratings User Comments (1)
 All time
For more information send a message to info at phpclasses dot org.