PDA

View Full Version : Restricting Download speed on attachements.


Milhouse
01-12-2004, 05:33 PM
At this point in time, if one is to download an attachement from our forums he will be able to use up all of the line as long as his internet connections allows him to.

What i was wondering, is it possibly to put a restriction on mysql attachemnts so that users can only download at say a maximum speed of 30k/s instead of the 200k/s they are getting ?

Thanx you

Andreas
01-12-2004, 06:42 PM
File attachment.php, at the very end

Replace
echo $attachmentinfo["$imagetype"];

With

// UploadBandwithLimitHack
// Original line: echo $attachmentinfo["$imagetype"];
$bandwidth = 30; // Desired max. bandwidth in KB/s.
$i = 0;
while ($i < strlen($attachmentinfo["$imagetype"])) {
echo substr($attachmentinfo["$imagetype"], $i, 1024);
$i += 1024;
flush();
usleep(1000000/$bandwidth);
}
// UploadBandwidthLimitHack


This might help, but isn't a good solution IMHO.

Milhouse
01-12-2004, 07:00 PM
hmm nope I was still able to download at higher then 30k/s with that. It just took forever for the download to start that's all. Anyother solutiosn anyone ?

Milhouse
01-12-2004, 07:06 PM
oh and BTW at the end of the file i have echo $attachmentinfo[filedata]; not what you posted above

Andreas
01-12-2004, 07:38 PM
Hmm ... what version do you use?
This is for RC2 and worked for me.

Milhouse
01-12-2004, 07:45 PM
Running vb 2.3.2 Did I post in the wrong section ?

Milhouse
01-12-2004, 07:51 PM
Also i do have a vb3 RC2 forum runnign where i just tried that and it was a no go as well.

Andreas
01-12-2004, 07:58 PM
Strange, does work for me. Well then - sorry for the mess.

NTLDR
01-12-2004, 08:03 PM
Quickly looking at the code I'd assume it works for images only.

Milhouse
01-12-2004, 08:52 PM
Quickly looking at the code I'd assume it works for images only.


That's what i assumed as well.

Which is not good for me. i need ti to essentially effect all attachements.

Any ideas from the gurus here?

cirisme
01-12-2004, 09:05 PM
That's what i assumed as well.

Which is not good for me. i need ti to essentially effect all attachements.

Any ideas from the gurus here?
Try finding this:

echo $attachmentinfo[filedata];

and changing to:

// UploadBandwithLimitHack
// Original line: echo $attachmentinfo['filedata'];
$bandwidth = 30; // Desired max. bandwidth in KB/s.
$i = 0;
while ($i < strlen($attachmentinfo['filedata'])) {
echo substr($attachmentinfo['filedata'], $i, 1024);
$i += 1024;
flush();
usleep(1000000/$bandwidth);
}
// UploadBandwidthLimitHack

This is essentially what was posted above, but for the filedata with vb2 itself :)

Milhouse
01-12-2004, 09:30 PM
I did that. All it did was make the download take longer to start, but once it started ti downloaded at the top speed it could and not the 30k i had set.

Zachery
01-12-2004, 09:31 PM
Try finding this:

echo $attachmentinfo[filedata];

and changing to:

// UploadBandwithLimitHack
// Original line: echo $attachmentinfo['filedata'];
$bandwidth = 30; // Desired max. bandwidth in KB/s.
$i = 0;
while ($i < strlen($attachmentinfo['filedata'])) {
echo substr($attachmentinfo['filedata'], $i, 1024);
$i += 1024;
flush();
usleep(1000000/$bandwidth);
}
// UploadBandwidthLimitHack

This is essentially what was posted above, but for the filedata with vb2 itself :)
whats the point? this would force users to WAIT longer to download an image or a file, why not let them get it asap ..?

Milhouse
01-12-2004, 10:03 PM
whats the point? this would force users to WAIT longer to download an image or a file, why not let them get it asap ..?

That is exaclty what i experience when downloading. I no want them to wait longer I just want to slow the speed at which they get it at.

Most users have a 100k/s line or higher... I want them to only be able to download my attachements at like 40k or so. Simply because we have files of 5+ megs..

when we have 100 users downloading those files at 100+k/s you can imagine what hapepsn to our line.

Zachery
01-12-2004, 11:07 PM
That is exaclty what i experience when downloading. I no want them to wait longer I just want to slow the speed at which they get it at.

Most users have a 100k/s line or higher... I want them to only be able to download my attachements at like 40k or so. Simply because we have files of 5+ megs..

when we have 100 users downloading those files at 100+k/s you can imagine what hapepsn to our line.
if anything slowing them down would put more stress on your line, a burst at 400kbps would get that file finished much faster

Milhouse
01-12-2004, 11:19 PM
if anything slowing them down would put more stress on your line, a burst at 400kbps would get that file finished much faster


Problem is we are getting bursts as high as 1400kbps and the datacenter is wanting more money.

Specially when these bursts are at times consecutive for like 30 minutes.

Also because of the high bursts at time the site it self becomes rather slow. While server loads at a minimum. What is happenign is some users are using up all the of the line downloading and leaving nothing or barely nothing for users who are just surfing. causing the site to drag.

If i could cap the downloads then it would be equal to all.

I have manage to get server side files to download at 40k/s if bigger then 1 meg, however that does not effect mysql attachements.

Any help would really be appricated.

Milhouse
01-13-2004, 02:18 AM
Is this not possible? Such hack?

Zachery
01-13-2004, 02:27 AM
Is this not possible? Such hack?
please wait more than 4 hours to bump a post,

maybe its time to find a differnt host with a bigger pipe. >.<

Milhouse
01-13-2004, 03:42 AM
please wait more than 4 hours to bump a post,

maybe its time to find a differnt host with a bigger pipe. >.<


Sorry about that.

cirisme
01-13-2004, 04:38 PM
I did that. All it did was make the download take longer to start, but once it started ti downloaded at the top speed it could and not the 30k i had set. It won't change download speed... but unlike the orginal, it will only give the download in sections at a time.

The original would only do this with the header which is why it took longer to start.

At least check the code to see it's different :rolleyes:

cirisme
01-13-2004, 04:41 PM
whats the point? this would force users to WAIT longer to download an image or a file, why not let them get it asap ..?
Um... duh? That's what he wants.

It frees the line so that it can serve other clients. The download speed may still SHOW 200k... but it should take longer than a 200k download.