Limit IP Script

software development

#1

Hi,

Does anyone know of a PHP script which will limit IPs to 2 when they are downloading files ? (So they can only have 2 connections to the server at once).

I made my own PHP script but it is actually serving the file and therefore keeping that php script active. My CPU usage on the machine has jumped up to 57%! I’ve disabled the script for now.

If there isn’t a good PHP script to do this, is it possible to make a htaccess file that would limit the IPs to 2 in certain folders instead?

Thanks.


#2

Your question is a little ambiguous: Do you want to limit the connections to 2 from at at time from a single IP address, or limit the connections to only 2 different IP addresses downloading at the same time?

I guess it boils down to what you mean by “they” - individual visitors (by IP address) or IP connections that are downloading?

–rlparker


#3

Ah sorry about that. Yeah I mean from a single IP address. So each user who say is downloading a file can only have 2 connections to the server at once.


#4

Thanks for the clarification! You did say you had been using a script to deal with this, so this suggestion my be “more of the same”, but is something like this method of limiting the number of downloads per client similar to what you are doing?

–rlparker


#5

Yeah it’s pretty similar to my script. The only difference is my script updates the database every x minutes in the while(!feof($fd)) { } part. Would you think that might be why it’s taking up alot of CPU resources?

Thanks for your help.


#6

I honestly don’t know, but it sounds like a reasonable deduction to make.

It should be easy enough to comment that database update out of the program as a debugging mechanism just to see what happens.

–rlparker