469,287 Members | 2,748 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,287 developers. It's quick & easy.

The best method to send a large file to client?

I have many text file with 1 to 2MB in size

currently, i use the method:

echo file_get_contents( $file_path );
are there any better method?

thanks.

Oct 5 '06 #1
12 7829
Hmm Uzytkownik <ho******@gmail.comwrote:
are there any better method?

ofc, you can gzip this file first you will send few kB not mB

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl

2be || !2be $this =mysql_query();
Oct 5 '06 #2
Hmm Uzytkownik <ho******@gmail.comwrote:
I have many text file with 1 to 2MB in size
what you mean send? send via email, send via browser or what?

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl

2be || !2be $this =mysql_query();
Oct 5 '06 #3

..:[ ikciu ]:. 寫道:
Hmm Uzytkownik <ho******@gmail.comwrote:
I have many text file with 1 to 2MB in size

what you mean send? send via email, send via browser or what?

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl

2be || !2be $this =mysql_query();
i mean read the content from the text file, and send to the browser

Oct 5 '06 #4

ho******@gmail.com 寫道:
I have many text file with 1 to 2MB in size

currently, i use the method:

echo file_get_contents( $file_path );
are there any better method?

thanks.
gzip take time, if many people access the page, my server will be
killed....

what i want to look for is if any method can send the file to apache
for display with getting back the content to the php first, i.e. i want
streaming, no matter the size of the file, even 1GB

echo file_get_contents( $file_path ); // no good, as content will be
passed back in the STACK during function call

// i want sth like...streaming
print_file_to_client( $file_path );

Oct 5 '06 #5
ho******@gmail.com schreef:
I have many text file with 1 to 2MB in size

currently, i use the method:

echo file_get_contents( $file_path );
are there any better method?

thanks.
Yup .. stream the file.

file($file_path);

foreach($file as $line)
{
echo $line;
ob_flush();
flush();
}

Arjen
Oct 5 '06 #6
ho******@gmail.com wrote:
ho******@gmail.com 寫道:
>I have many text file with 1 to 2MB in size

currently, i use the method:

echo file_get_contents( $file_path );
are there any better method?

thanks.
gzip take time, if many people access the page, my server will be
killed....

what i want to look for is if any method can send the file to apache
for display with getting back the content to the php first, i.e. i want
streaming, no matter the size of the file, even 1GB

echo file_get_contents( $file_path ); // no good, as content will be
passed back in the STACK during function call

// i want sth like...streaming
print_file_to_client( $file_path );
If you want to stream the file (without compressing it) then why not use
fread to read small "chunks" of the file?

Something like this...

$chunk = (8024);
$buffer = '';
$handle = fopen($filename, 'rb');
if ($handle === false) die();
while (!feof($handle))
{
$buffer = fread($handle, $chunk);
print $buffer;
flush();
ob_flush();
}
fclose ($handle);

-- -------------------- Arkady Renko Network Admin To email me directly
Remove all capitals and underscores from my posting address
Oct 5 '06 #7
Hmm Uytkownik <ho******@gmail.comwrote:
gzip take time, if many people access the page, my server will be
killed....
you right, i thought you send it via mail or allow user to download it, when
you only display it you you can use require function (but you have right
there is no php code or just show it like a data)
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl

2be || !2be $this =mysql_query();
Oct 5 '06 #8
why don't u use readfile()? http://ro2.php.net/readfile
it does exactly what you want, and is much faster than reading the file
and echo'ing it

..:[ ikciu ]:. a scris:
Hmm Uytkownik <ho******@gmail.comwrote:
gzip take time, if many people access the page, my server will be
killed....

you right, i thought you send it via mail or allow user to download it, when
you only display it you you can use require function (but you have right
there is no php code or just show it like a data)
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl

2be || !2be $this =mysql_query();
Oct 5 '06 #9
NC
On Oct 5, 12:17 am, howac...@gmail.com wrote:
>
I have many text file with 1 to 2MB in size

currently, i use the method:

echo file_get_contents( $file_path );

are there any better method?
Yes. Use readfile():

http://www.php.net/readfile

Cheers,
NC

Oct 5 '06 #10
Arjen wrote:
ho******@gmail.com schreef:
>I have many text file with 1 to 2MB in size

currently, i use the method:

echo file_get_contents( $file_path );
are there any better method?

thanks.

Yup .. stream the file.

file($file_path);
You'll run out of memory very quickly using file(...) or
file_get_contents(...) on big files.

C.

Oct 5 '06 #11

NC 寫道:
On Oct 5, 12:17 am, howac...@gmail.com wrote:

I have many text file with 1 to 2MB in size

currently, i use the method:

echo file_get_contents( $file_path );

are there any better method?

Yes. Use readfile():

http://www.php.net/readfile

Cheers,
NC
thanks all...

seems readfile() is the best method

Oct 6 '06 #12
NC wrote:
On Oct 5, 12:17 am, howac...@gmail.com wrote:

I have many text file with 1 to 2MB in size

currently, i use the method:

echo file_get_contents( $file_path );

are there any better method?

Yes. Use readfile():

http://www.php.net/readfile
When I read the responses in this thread, I was wondering what
happened to c.l.php (obvious shortage of PHP saints). Fortunately,
still Nikolai Chuvakhin is hacking PHP...:-)

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Oct 6 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

24 posts views Thread by Joerg Schuster | last post: by
reply views Thread by zhimin | last post: by
reply views Thread by PJ | last post: by
1 post views Thread by Nawaz Ijaz | last post: by
5 posts views Thread by Hardy Wang | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.