0

I try to download big file from url to my server, but I need to set download speed limit, for example 100kb/s.

This is my code:

<?php
    $random = rand(00000000,999999999);
    $file_url = "BIG FILE URL";

    $get_name = basename($file_url);
    $file_new_name = $random.$get_name;

    $get_file = file_get_contents($file_url);
    $put_file = file_put_contents($file_new_name, $get_file);

    if( $put_file ){
        echo "Done!";
    }
?>

Code is working but fast speed! I need speed to be 100kb/s.

user3492381
  • 167
  • 9

1 Answers1

0

You can try mod_bandwidth or more advanced mod_cband.

Quote from mad_bandwidth site:

Mod_bandwidth is a module for the Apache webserver that enable the setting of server-wide or per connection bandwidth limits, based on the directory, size of files and remote IP/domain.

Quote from mod_cband site:

mod_cband is an Apache 2 module provided to solve the problem of limiting users’ and virtualhosts’ bandwidth usage. The current versions can set virtualhosts’ and users’ bandwidth quotas, maximal download speed (like in mod_bandwidth), requests-per-second speed and the maximal number of simultanous IP connections (like in mod_limitipconn)

Here is tutorial about how to use cband to limit download speed.

ashkufaraz
  • 5,179
  • 6
  • 51
  • 82