SEO Software
+ Reply to Thread
Results 1 to 2 of 2

Thread: Anybody know how to limit bandwidth speed using php?

  1. #1

    Default Anybody know how to limit bandwidth speed using php?

    Hello Guys.

    I need to limit bandwidth speed output from a download script i made, does anyone have examples using php?

    Thanks in advance.


  2. SEO Software

  3. #2

    Default

    Code:
    // The file that will be sent to the user
    $your_file = 'file.zip';
    // Rename the file name
    $new_file = 'new-filename.zip';
    // Set the download speed limit (70 kb/s)
    $download_speed = 70;
    
    if(file_exists($myl_file) && is_file($my_file)) {
        // Headers
        header('Cache-control: private');
        header('Content-Type: application/octet-stream');
        header('Content-Length: '.filesize($my_file));
        header('Content-Disposition: filename='.$new_file);
        // Flush the content
        flush();
        // File stream
        $file = fopen($my_file, "r");
        while (!feof($file)) {
            // Send the current part of the file to the browser
            echo fread($file, round($download_speed* 1024));
            // Flush the content to the browser
            flush();
            // Sleep one second
            sleep(1);
        }
        // Close file stream
        fclose($file);
    }
    
    else {
        die('Error: The file '.$my_file.' does not exist!');
    }
    Use this scriprt for limit bandwidth speed or you can also use QoS Bandwidth Throttle in PHP.

+ Reply to Thread

Similar Threads

  1. PHP loop through database and limit number of entries
    By gilbertsavier in forum PHP Help
    Replies: 1
    Last Post: 08-24-2009, 09:16 PM
  2. Narrow Your Market, But Don't Limit It
    By Kay in forum Article Repository
    Replies: 0
    Last Post: 08-19-2009, 06:40 PM
  3. PHP loop through database and limit number of entries
    By gilbertsavier in forum PHP Help
    Replies: 0
    Last Post: 07-17-2009, 07:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

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