Sometimes you need to limit the speed at which users download files. For more information, see

Source: Internet
Author: User
(The company has a need to prevent people from constantly downloading and seeing it on others' websites) the following translation is from Google, which can be used to limit the speed of file download. It intercepts the output of PHP scripts and provides a buffer for the browser. It is called the number of bytes each time. Class from the last measurement time PHP output buffer rinse, and keep for a period of time,

(The company has a need to prevent people from constantly downloading and seeing it on others' websites) the following translation is from Google, which can be used to limit the speed of file download. It intercepts the output of PHP scripts and provides a buffer for the browser. It is called the number of bytes each time. Class from the last measurement time PHP output buffer rinse, and keep for a period of time,

(The company has a need to prevent people from constantly downloading and seeing it on others' websites)
Translated by Google
This class can be used to limit the speed of object download.

It intercepts the output of PHP scripts and provides a buffer for the browser. It is called the number of bytes each time.

Class from the last measurement time PHP output buffer rinse, and maintain for a period of time if the average download speed for PHP exceeds the given limit.

---------------------------------------------------------------------------
There are three different bandwidth shaping mechanisms to ensure adequate service quality:

1) The burstable transmission rate will be switched off X bytes and then sent to the user (this helps to quickly send small images and limit the download speed and huge file size)

2) The burstable transmission rate will be disabled for a period of time. In seconds, it will return to the standard throttling speed.

3) The burst transmission rate will not be activated, and the download speed limit will be constant (in this case, throughout the download process $ configuration> burstLimit must be equal to the configuration-> rateLimit) PHP

Source code and demo:Source code source demonstration Source

 BurstTimeout = 30; // set burst transfer rate to 50000 bytes/second $ config-> burstLimit = 50000; // set standard transfer rate to 15.000 bytes/second (after initial 30 seconds of burst rate) $ config-> rateLimit = 15000; // enable module (this is a default value) $ config-> enabled = true; // start throttling $ x = new Throttle ($ config); // A http://www.codepearl.comheader ("Content-type: application/force-download "); header ("Content-Disposition: attachment; filename = \" test.txt \ ""); header ("Content-Length: 60000000"); // generate 60.000.000 bytes file. for ($ I = 0; $ I <60000000; $ I ++) {echo "";}
 BurstSize = 500000; // set burst transfer rate to 50000 bytes/second $ config-> burstLimit = 50000; // set standard transfer rate to 15.000 bytes/second (after initial 30 seconds of burst rate) $ config-> rateLimit = 15000; // enable module (this is a default value) $ config-> enabled = true; // start throttling $ x = new Throttle ($ config); // A http://www.codepearl.comheader ("Content-type: application/force-download "); header ("Content-Disposition: attachment; filename = \" test.txt \ ""); header ("Content-Length: 60000000"); // generate 60.000.000 bytes file. for ($ I = 0; $ I <60000000; $ I ++) {echo "";}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.