PHP Classes

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: 286 All time: 7,542 This week: 123Up
Version License PHP version Categories
traffic-jam 0.1GNU General Publi...5HTTP, PHP 5, Security


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: 59
All time rank: 608 in United States United States
Week rank: 16 Up2 in United States United States Up
Innovation award
Innovation award
Nominee: 32x

Winner: 7x


//traffic jam class 0.1 beta

$tJam = new trafficJam();

$jamCode = $tJam->jamTraffic();

if( !empty(
$jamCode) ){
        <title>Traffic Jam Example</title>
        <a href="example.php">Click Me</a>
        <p>To test, click link as a normal human would and then click as quickly as possible. Depending on your humanSpeed and jamTime settings, you should get jammed.</p>
        <p>Once jammed, you can refresh the page or visit again later to see countdown to when you will be allowed back in</p>


Class: trafficjam Version: 0.1 bets 10/14/2015 Copyright 2015 Wagon Trader, All Rights Reserved Description: 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 Files: 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 Installation: Upload files to a web accessible location on your server (eg. public_html) Configuration: /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 Usage: Refer to example.php file for usage example. Refer to trafficjam.class.php file for instructions on using methods Changelog 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,542
This week:123Up
User Ratings User Comments (1)
 All time