download speed limit (txt files solved..)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MaNiAC
Forum Newbie
Posts: 20
Joined: Fri Dec 23, 2005 4:20 am

download speed limit (txt files solved..)

Post by MaNiAC »

Hi.

I want to import a txt file, but I also want it to keep it's <br>'s. Right now, it's just put on one line. Anyone knows how to solve it?

Source:

Code: Select all

include("files/$id");
Result:

Code: Select all

1 2 3 4 5 6 7 8 9 this is a test
Wanted result:

Code: Select all

1
2
3
4
5
6
7
8
9
this is a test

ALSO,

does any1 know how to set a max. download speed. I'd like my download to not go quicker then say 10kb/s. Can you plz help me on that?

Thanx in advance,

MaNiAC
Last edited by MaNiAC on Mon Dec 26, 2005 10:26 am, edited 1 time in total.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Well file() loads a text file with one line on each element of an array
so...

Code: Select all

$ar = file('file.txt');
foreach($ar as $line) {
echo $line.'<br />';
}

for bandwidth capping what you need to do is start an output buffer and control how often it is flushed, lets say you have 1024 bytes of data in the buffer and you want to send it at 10kb/sec

take the reciprocal of the rate to send it at (10kb/s) so .1
wait .1 seconds then send .1kb of data, this will average out to 10kb/sec

usleep() is the function that will "wait .1 seconds"


there is also an apache module called mod_bandwidth but it effectively uses the same method as this
Last edited by josh on Mon Dec 26, 2005 10:21 am, edited 2 times in total.
MaNiAC
Forum Newbie
Posts: 20
Joined: Fri Dec 23, 2005 4:20 am

Post by MaNiAC »

Thanx man.. much appreciated :)
Post Reply