If your web is attacked by botnet, you can include this script into it and prevent server crash.
Just set up a number of allowed approaches and controled time. (for ex. 1000 users/1 min)
If there were connected 1001 users in 1 minute, web will be shuted down by generated htaccess file.
There is a second file(you should execute it with cron) to automaticly remove htaccess file if there will be less than 1001 users per minute.