[Ask] Download Limiter On PHP Scripts
Link |
by berantacan
on 2008-08-14 02:08:38
|
Guys, I need help here. I have a server, hosting my personal site using PHP/Apache/MySQL. Truth is, lately visitors downloading too much from my site, and sometimes even caused crash. After a quick look at the log file, I concluded that most visitors download files using Download Accelerator. I've put an announcement saying a maximum parallel download of 2 connection per download, and a maximum 4 download at a time, or banned otherwise, but most doesn't even understand what that supposed to mean. Now the question is.... supposed i have a file called "music.mp3", and a PHP Script called "download.php", also in the same directory. What script should I write in "download.php" so that it generates a maximum of 2 connection per download, and a maximum 4 download at a time? any help would be appreciated. thanks.
Seizon senryaku, shimashouka?
|
Re: [Ask] Download Limiter On PHP Scripts
Link |
by
on 2008-08-14 02:54:14 (edited 2008-08-14 02:54:51)
|
This is work best left to apache. However, it can be done in PHP, too. function connectionCount() { $count = 0; $quad = explode('.', $_SERVER['REMOTE_ADDR']); $ip = sprintf('%02X%02X%02X%02X', $quad[3], $quad[2], $quad[1], $quad[0]); // local port 80 remote, ip matches, status is connected foreach(file('/proc/net/tcp') as $line_num => $line) if("0050 $ip" == substr($line, 15, 13) && substr($line, 34, 2) == '01') $count++; return $count; }If your /proc/net/tcp doesn't have the same formatting as mine, you may need to edit this code. |
Re: [Ask] Download Limiter On PHP Scripts
Link |
by berantacan
on 2008-08-14 17:12:08
|
woah neat! what more could I expect? a word of wisdom from the master himself. gee, thanx Gendou!
Seizon senryaku, shimashouka?
|