AnimeSuki Forums

Register Forum Rules FAQ Members List Social Groups Search Today's Posts Mark Forums Read

Go Back   AnimeSuki Forum > Support > Tech Support


Thread Tools
Old 2007-09-01, 12:33   Link #1
Join Date: May 2006
Location: Kuurne (Belgium)
Age: 28
Daily bandwidth limit (php) script?

(don't know if it's the right section, but couldn't figure it would fit in anywhere else)

hey, I've been searching everywhere to get my hands on a easy script that allows to set a daily download-limit for large files on my webserver. Anyone has such a script and willing to share it? ^^
Shi-chan is offline   Reply With Quote
Old 2007-09-01, 17:01   Link #2
Join Date: Dec 2005
Location: New Jersey
Age: 34
Send a message via ICQ to Epyon9283 Send a message via AIM to Epyon9283
Don't even know if it would be possible just using a php script.

There are apache modules to limit bandwidth. I'm sure IIS probably has the same functionality.
Epyon9283 is offline   Reply With Quote
Old 2007-09-01, 22:06   Link #3
AS Oji-kun
Join Date: Nov 2006
Location: Anatae
Age: 67
You need to write a PHP wrapper that keeps track of the number and sizes of the files downloaded. (The simplest way would be to write running totals to a text file in a directory to which the web server user has rights.) When the limits are exceeded the wrapper displays a "sorry, no more today" message. I'd have it record the time of day in the file as well; the first time the script is accessed after midnight you'd just zero the totals.

I've used a wrapper like this to limit file downloads to authorized users. Here's a code snippet:


header("Content-Type: ".$thisdoc["mimetype"]);
header("Content-Disposition: inline; filename=".$thisdoc["filename"]);

### Open the file and display it
These commands send two HTTP headers that tell the client the name and mimetype (e.g., "video/x-matroska") of the content to be transferred, then opens the file and sends it unaltered to the client with the fpassthru() command. There can be no text outside the php tags before the header() commands or you'll get an error. (Blank spaces outside the php tags are sent directly to the client. Once any text is sent you've ended the HTTP dialogue so you cannot send the headers. If that's not clear it's discussed in the PHP manual.) The script must have the <?php start tag in column 1, line 1 of the script and all text before the fpassthru() command must reside inside the php tags.

I usually manage this stuff by storing the information about the files in a database (PostreSQL is my choice), but that might be overkill for you. An easier solution is to write the download URIs in a form like "/getfile.php?name=myfile.ext" and have the script use the file's extension to determine which mimetype to send in the HTTP headers. A simple PHP array like :
that maps extensions to mimetypes should be easy to whip up if you aren't distributing a very wide variety of filetypes.

I leave the rest as an exercise for the reader.

Last edited by SeijiSensei; 2007-09-02 at 10:33. Reason: fixed typo in array definitions
SeijiSensei is offline   Reply With Quote
Old 2007-09-02, 10:22   Link #4
Join Date: May 2006
Location: Kuurne (Belgium)
Age: 28
Thx so much ^^, figured something out with your php wrapper and wrote my own script, it's very basic but does the job, thx again
Shi-chan is offline   Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -5. The time now is 00:02.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2017, vBulletin Solutions Inc.
We use Silk.