Login   Register  
PHP Classes
elePHPant
Icontem

QoS Bandwidth Throttle in PHP: Limit the speed of files served for download

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   Screenshots Screenshots   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2011-03-22 (3 years ago) RSS 2.0 feedStarStarStarStar 76%Total: 1,647 This week: 3All time: 2,205 This week: 576Up
Version License PHP version Categories  
bandwidth-throttler 1.1.5GNU Lesser General Publ...5.2.0HTTP, PHP 5, Files and Folders, Syste..., P...
Description Author  

This class can be used to limit (throttle) the speed of files served for download.

It intercepts the PHP script output by setting a buffering handler that is called every time a given number of bytes are served to the browser.

The class measures the time since the last time the PHP output buffer was flushed and hold on PHP for a while if the average download speed is above a given limit.

---------------------------------------------------------------------------
There are three different bandwidth shaping mechanisms to ensure adequate Quality of Service:

1) burst transfer rate will be switched off after sending X bytes to the user (this can be helpful to send small images quickly, and limit the download speed of huge files)

2) burst transfer rate will be switched off after given period of time in seconds, then it will revert to the standard throttle speed

3) burst transfer rate will not be activated at all, the download speed limit will be constant during the whole downloading process (in this case $config->burstLimit must be equal to the $config->rateLimit)

Innovation Award  
PHP Programming Innovation award nominee
January 2011
Number 2


Prize: One copy of DWebPro Standard License
If too many users access a server to download files or other resources, the server may reach to the bandwidth usage limit and the access to the server may become too slow to all users.

A solution for this problem consists in throttling the download speed, i.e., limiting the speed by which the files are served to the users that are downloading them.

This class implements a clever download speed throttling approach controlled by PHP.

It consists in capturing the output of the download scripts into a buffer, flush the buffer at a rate that does not exceed a given limit by introducing eventual pauses if the file is served at a speed above the limit.

Manuel Lemos
Picture of Artur Graniszewski
Name: Artur Graniszewski is available for providing paid consulting. Contact Artur Graniszewski .
Classes: 13 packages by
Country: Poland Poland
Age: 32
All time rank: 3295 in Poland Poland
Week rank: 194 Up7 in Poland Poland Down
Innovation award
Innovation award
Nominee: 7x

Winner: 1x

Screenshots  
  • speed_decrease.PNG
  Files folder image Files  
File Role Description
Plain text file throttler.php Class Main class
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file example2.php Example Example script using data size as the bandwidth limit factor
Accessible without login Plain text file license.txt Lic. LPGP license
Accessible without login Plain text file readme.txt Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 0%Total:1,647All time:2,205
 This week:3This week:576Up
User Ratings User Comments (1)  
 All time
Utility:96%StarStarStarStarStar
Consistency:96%StarStarStarStarStar
Documentation:93%StarStarStarStarStar
Examples:92%StarStarStarStarStar
Tests:-
Videos:-
Overall:76%StarStarStarStar
Rank:47
 
Ty for this nice class.
2 years ago (Martin D?dík)
75%StarStarStarStar