Results 1 to 3 of 3

Thread: Download Speed Limiter

  1. #1

    Thread Starter
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909

    Download Speed Limiter

    PHP Code:
    function getext($file) {
    return 
    $ext=substr(strrchr($file'.'), 1);
    }

    function 
    filesize_url($url){
       return (
    $data = @file_get_contents($url)) ? strlen($data) : false;
    }

    function 
    sendfile($filename) {
    global 
    $type,$set,$ext;
    $file="http://www.some-site.net/".$filename;
    $ext=getext($filename);
    $mtype=$type[$ext][type];
    if(
    ini_get('zlib.output_compression')) {ini_set('zlib.output_compression''Off');}
    flush();
    $file_size filesize_url($file);
    $fp fopen($file'r');
    header('Expires: 0');
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: $mtype");
    header("Accept-Ranges: bytes");
    #header("Content-Disposition: attachment; filename=\"" . $filename ."\"");
    $user_agent strtolower ($_SERVER['HTTP_USER_AGENT']);
    if ((
    is_integer (strpos($user_agent"msie"))) && (is_integer (strpos($user_agent"win")))) {
    header"Content-Disposition: filename=".basename($filename).";" );
    } else {
    header"Content-Disposition: attachment; filename=".basename($filename).";");
    }
    header("Content-transfer-encoding: binary");
    header("Content-Length: $file_size");
    flush();
    $speed=round(25*1024);
    while (!
    feof($fp)) 
    {
        
    set_time_limit(0); 
        print(
    fread($fp$speed)); 
        
    flush();
        
    sleep(1);
    //end while
    fclose ($fp);
    die; 
    }

    sendfile("testfile.exe"); 
    I've been playing around with this snippet of code I found that theoretically is suppose to limit the download speed from the browser to whatever amount I specify. However it seems no matter what it is limiting the speed to about 8.5 to 9kb/s

    Eventhough I have it set to download at 25kb/s. Any ideas as to whats wrong or a way to limit the speed of a file download that is located remotely?

  2. #2
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: Download Speed Limiter

    u sure its not doin that just cause ur connection can only support that?

  3. #3
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Download Speed Limiter

    The problem with scripts like this, is that the code inside the loop takes time to execute too. Although it may be negligable on a per interation basis, it begins to add up. What effect does it have then you change the speed to 1kb per second?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width