[web] Bandwidth Management and File Streaming on Apache

Started by
3 comments, last by markr 18 years, 6 months ago
Hello. Im currently making my CMS, and when I tried to design the downloads module, some questions popped up in my mind, probably they are not related at all with the CMS, but I still need some enlightening. 1. I dont understand why people would like to download several files from a server. Lets put an example, Slackware CD set (4 CDs). Pretend I try to download it from a very fast server, and my download speed is that of 100 kbps average (1 Mbps ADSL perhaps). a) If I try to download CD #1, Ill likely get full speed (100 kbps), what is the point of downloading 2 files at the same time? Wont I just get 50 kbps for each, in which case, isnt it the same downloading 1 at a time, than two? b) Now lets pretend the server is really slow, and I get a download speed of 25 kbps per file. Then, if I try to download 2 at the same time, will I get 25 kbps per CD, which means Ill be able to take full advantage of my download speed? Or do servers cap the download speed by IP/file (either one or both???) which means, 25 kbps is the max download speed I can get from that server (IP capping) or otherwise, I could download the 4 of them at the same time (file capping)? 2. Talking about bandwidth issues, how can I limit the bandwidth of an apache server, for example, to test it on a localhost level (and then check out the behaviour of the CMS when run in a slow server and such)? Maybe an http directive, or it goes way beyond of that... Maybe what Im implying is to play to be a hosting company, just for fun testing purposes... And while we are at it... How could I play to have several hosted sites... VPNs and a free solution like zpanel??? 3. I am aware of the technique, that you can put in practise, in php for example, when you stream the file to the client, rather than the client making a request to the HTTP server, which basically means you cant use a download manager to resume the file, as it is streamed by a script, and not by the server itself. Now, the question is, Ive seen some of those free file sharing services, and how they create their download links e.g http://server.org/files/12345/file.rar And the above link would be streamed by an script rather than sent by the http server. How can I do this? My thought (and I could be blatantly wrong), is to register several file extensions in apache, to be handled by the php module/CGI. That way, when requesting the example link, the client would be actually calling a php script rather than requesting the .rar from the server... Is this feasible? I think it could be at some extenct, but according to my knowledge, it would imply to copy a new script, then give it some random name (file.rar) whenever there is a new download... or is there a way to have a single URI to be handled by a same script (perhaps mod_rewrite)? Or how can I implement such behaviour? Maybe by means of using some directives in htaccess files, or...? Thats all I guess. Thanks a bunch for your time :)
Advertisement
1) It's not guaranteed to be faster when downloading multiple files, but it can be. As you yourself point out, it depends on where the bottleneck is. At least it's not going to be slower. I can give you a non-technical reason too: ease of use. If I am at a site, I can start downloading multiple files and then continue browsing. Also, I can start many downloads and go do something else (like sleeping [wink]).

2) No clue actually....

3) You would use mod_rewrite to change http://server.org/files/12345/file.rar into http://server.org/download.php?name=file.rar and then have a PHP script that opens file.rar and streams it to the client. Before you off doing this: Why would you want to prevent people from using their download managers in the first place?

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

Quote:I dont understand why people would like to download several files from a server. Lets put an example, Slackware CD set (4 CDs).
Sometimes the combined speed of the downloads is faster than the maximum speed of a single download. Sometimes it's not.

Quote:Talking about bandwidth issues, how can I limit the bandwidth of an apache server, for example, to test it on a localhost level (and then check out the behaviour of the CMS when run in a slow server and such)?

You could use mod_throttle, or let your OS network stack handle it if it can.

Quote:You would use mod_rewrite to change http://server.org/files/12345/file.rar into http://server.org/download.php?name=file.rar and then have a PHP script that opens file.rar and streams it to the client. Before you off doing this: Why would you want to prevent people from using their download managers in the first place?

No need to use mod_rewrite. Any path info after the base URI to a PHP script is passed to the PATH_INFO environment variable. For example, index.php/myfile.tar will be directed to index.php with "/myfile.tar" in PATH_INFO.
Free Mac Mini (I know, I'm a tool)
Quote:Original post by igni ferroque
Quote:Talking about bandwidth issues, how can I limit the bandwidth of an apache server, for example, to test it on a localhost level (and then check out the behaviour of the CMS when run in a slow server and such)?

You could use mod_throttle, or let your OS network stack handle it if it can.

Seems like teh winna.

Quote:Original post by Sander
Before you off doing this: Why would you want to prevent people from using their download managers in the first place?

No I dont want to. Just wanted to know how it works actually. I hate webmasters that do so [grin]

Thanks a lot guys. That clarifies my doubts.

Cheers!


"Download managers"* are just user agents which are capable of resuming file transfers. They can do this by using the HTTP 1.1 "range" headers which allow a client to get just part of a file. Apache (and all other web servers) supports this and it's enabled by default.

The reason that download managers might not work, is because it's served by a cgi script, php page etc, which doesn't support these headers.

If the script was made to support these headers, it would work.

Mark

* Such as the one built into Firefox

This topic is closed to new replies.

Advertisement