Page 1 of 1

download speed limit (txt files solved..)

Posted: Mon Dec 26, 2005 9:46 am
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

Posted: Mon Dec 26, 2005 10:14 am
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

Posted: Mon Dec 26, 2005 10:18 am
by MaNiAC
Thanx man.. much appreciated :)