Managing download speed per user?

Discussion in 'Programming/Scripts' started by edge, Feb 4, 2007.

  1. edge

    edge Active Member Moderator

    I've just finished a filehosting script / site, and now I'm thinking of adding a "premium" account part.

    The Non premium users get a slower download speed.

    I was thinking of using "mod_bandwidth" or "mod_cband", but I do not think that this will work! (I also have no clue how to set this with PHP)

    Anyone here who might have an idea on how I could set a "custom" download speed per IP?
     
  2. falko

    falko Super Moderator ISPConfig Developer

  3. edge

    edge Active Member Moderator

    Thanks Falko, I'll have a look at it..

    I'm now doing it this way

    Code:
    $speed = 10; //in KB
    $file2push = fopen($file,'r');
    
     while($temp = fread($file2push,round($speed*1024))){
     	    echo $temp;
     	    flush();
     	    sleep(1);
     }
     fclose($file2push);
    
    Problem is the sleep(1). It should sleep for one sec. but for some reason it's not really doing this.
     
  4. falko

    falko Super Moderator ISPConfig Developer

    How do you know? Have you tried with higher values (e.g. sleep(10)) to see if it really slows down?
     
  5. edge

    edge Active Member Moderator

    The above script is working fine from 1KB ($speed = 1) till arround 15KB ($speed = 15)

    Problem is when I set the $speed = to lets say 100

    The file should download at 100 KB, but it does not get above +/- 15KB.
    Even when I set $speed to lets say 200.. The download does not get above +/- 15KB

    Now when I change the sleep(1); to usleep(78000); (78000 micro seconds), and the $speed = 100 the download does speed up to arround 100KB
     

Share This Page