Forum Moderators: coopster
I would like to be able to throttle (control the rate at which) the file downloads. Instead of perhaps a normal 300k rate, throttle it to 30k, for example. This is done to encourage them to pay a subscription fee to access the full download speed - a common practice in my gaming genre.
I am currently on a shared hosting website; not ideal, I know, and will eventually migrate over to my own server. I'm guessing this might make throttling impossible?
I am running the website on the popular Content Management System, Joomla (which is PHP based).
I see other websites doing it - how do I implement it?
I'm guessing that it would be a stand-alone program that works inside Apache to do this? I'm not a programmer by any stretch, and would have to probably have it outsourced out; I'm just wondering how it is done, and what I need to make it happen.
Any light you can shed on this would be very helpful!
<?php
$file = "/path/to/file"; // path to file
$speed = 16; // 16 kb/s download rate limitheader("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);
?>