How to limit downloading speed?
Im tryin to make a script that will limit download speed, for instance.... free user 2 k/b's per second.
Advance user 10 k/b's per second.
Is this possible with-in PHP?
Thanks, for help...... Todd
You could try using the following functions: fopen() fread() sleep() flush()
<?php $file = "test.mp3"; // file to be send to the client $speed = 8.5; // 8,5 kb/s download rate limit if(file_exists($file) && is_file($file)) { header("Cache-control: private"); header("Content-Type: application/octet-stream"); header("Content-Length: ".filesize($file)); header("Content-Disposition: filename=$file" . "%20"); flush(); $fd = fopen($file, "r"); while(!feof($fd)) { echo fread($fd, round($speed*1024)); flush(); sleep(1); } fclose ($fd); } ?>
I tried that one (seen it in php.net manual). it dosnt download the full file. it cuts 247kb into the file......
Have you tried mod_bandwidth for Apache?
No I havn't, I will check it out.... Thanks. Todd