473,387 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 8041
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Joerg Schuster | last post by:
Hello, I am looking for a method to "shuffle" the lines of a large file. I have a corpus of sorted and "uniqed" English sentences that has been produced with (1): (1) sort corpus | uniq >...
2
by: Brian | last post by:
Hi all, I have an xml document that can contain 248 nodes with each node containing different fields. There is the possibility that there will be more nodes. Each node can have up to 30...
0
by: zhimin | last post by:
Hi, I'm writing a program to send large file(100m) through dotnet using TCPListener & TCPClient, I'm sending the file with a ask and response loop: 1. Client send a flag 1 to server indicate it...
0
by: PJ | last post by:
I have the following code snippet to send a file stored as an image data type from sql server: Protected Sub StreamFile(ByVal fileItem As MyFile) Dim offset As Integer Dim buffer As Integer =...
1
by: Nawaz Ijaz | last post by:
Hi All, Just need to know that how can it be possible to upload large file in chunks of bytes. Suppose i have a large file (100 MB) and i want to upload it in chunks (say 20 KB). How can this be...
5
by: Hardy Wang | last post by:
Hi all, I am new to WSE 3.0, and currently reading the document shipped with installation. From sample provided (see below), I created WSE service side code, but how can I consume stream returned...
0
by: nayakvishalv | last post by:
I am trying to send file to a remote server. The file size is 28MB. When i use put command i can send only 4kb of data. Can anyone please help me on this? Its kinda urgent Thanks in...
5
by: Eric Fortin | last post by:
I have a disconnected handheld device that I want to send the results of the day to a database through a web service (on an intranet) What's the best method to do this? XML? Tab...
2
by: kashifjawed | last post by:
I'm developing a c# asynchronous socket application for tranfering file or large data from client to server and server to client as well in chunks. Application sometimes transfer file from client...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.