<?xml version="1.0" encoding="UTF-8"?><!-- generator="bbPress" -->

<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
>

<channel>
<title>Forums Topic: Limit the speed of download with PHP</title>
<link>http://www.tutorialhelpdesk.com/forum/</link>
<description>Tutorialhelpdesk programming forums</description>
<language>en</language>
<pubDate>Fri, 21 Nov 2008 21:59:19 +0000</pubDate>

<item>
<title>ioana on "Limit the speed of download with PHP"</title>
<link>http://www.tutorialhelpdesk.com/forum/topic/limit-the-speed-of-download-with-php#post-20</link>
<pubDate>Fri, 04 Jul 2008 11:36:33 +0000</pubDate>
<dc:creator>ioana</dc:creator>
<guid isPermaLink="false">20@http://www.tutorialhelpdesk.com/forum/</guid>
<description>&#60;p&#62;Hi! I recently stumbled upon this function which seems to be pretty handy if you have a lot of downloads from your website and you want to limit the download speed at which your visitors download files. Have a look:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;// local file that should be send to the client
$local_file = &#38;#39;test-file.zip&#38;#39;;
// filename that the user gets as default
$download_file = &#38;#39;your-download-name.zip&#38;#39;;

// set the download rate limit (=&#38;gt; 20,5 kb/s)
$download_rate = 20.5;
if(file_exists($local_file) &#38;#38;&#38;#38; is_file($local_file)) {
    // send headers
    header(&#38;#39;Cache-control: private&#38;#39;);
    header(&#38;#39;Content-Type: application/octet-stream&#38;#39;);
    header(&#38;#39;Content-Length: &#38;#39;.filesize($local_file));
    header(&#38;#39;Content-Disposition: filename=&#38;#39;.$download_file);

    // flush content
    flush();
    // open file stream
    $file = fopen($local_file, &#38;quot;r&#38;quot;);
    while(!feof($file)) {

        // send the current file part to the browser
        print fread($file, round($download_rate * 1024));    

        // flush the content to the browser
        flush();

        // sleep one second
        sleep(1);
    }    

    // close file stream
    fclose($file);}
else {
    die(&#38;#39;Error: The file &#38;#39;.$local_file.&#38;#39; does not exist!&#38;#39;);
}&#60;/code&#62;&#60;/pre&#62;</description>
</item>

</channel>
</rss>
