Greetings
I want to limit the speed of download from my site. And want to prevent any client from downloading more than one file at the same time.
To do this.. I have written a PHP script (after searching the web and php.net). which uses these functions (and others):
fopen() - fread() - fwrite() - fclose() - flush()
To control the speed of downloading process.. fread() function was used. like this:
PHP Code:
$fp = fopen("$file",'r');
//start buffered download
while(!feof($fp) && connection_status() == 0)
{
//reset time limit for big files
set_time_limit(0);
$_fread = fread($fp, 1024*$speed);
print($_fread);
flush();
sleep(1);
}
fclose($fp);
My question is: is there any problem to use this script? will it make any problem to the server or increase the load? will it affect the CPU resources?
Notice that there is many visitors are downloading from my site. I'll apply this script on all (rar, pdf, zip) files in my site.
Please tell me whether to use this script or not. If not: what is the alternative? How can I perform this limitation?
My host provider is: 1&1
Thank you in advance 
|