473,549 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_conten ts( $file_path );
are there any better method?

thanks.

Oct 5 '06 #1
12 8054
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_conten ts( $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_conten ts( $file_path ); // no good, as content will be
passed back in the STACK during function call

// i want sth like...streamin g
print_file_to_c lient( $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_conten ts( $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_conten ts( $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_conten ts( $file_path ); // no good, as content will be
passed back in the STACK during function call

// i want sth like...streamin g
print_file_to_c lient( $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_conten ts( $file_path );

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

http://www.php.net/readfile

Cheers,
NC

Oct 5 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
7261
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 > corpus.uniq corpus.uniq is 80G large. The fact that every sentence appears only
2
3109
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 elements. What do you suggest is the best way to parse through this document? Should I create a class and deserialize the xml into it? Should I...
0
913
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 has data send to server. 2. Client send the buffer block size. 3. Client send the actual buffer to the server. 4. Server send a flag 1 to client...
0
3927
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 = 8192 Dim textPtr As System.Data.SqlTypes.SqlBinary = MyFactory.GetFilePtr(fileItem.ID, FileScale.Original) Response.Clear()
1
2875
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 done as "Simple html File Upload Control" upload file in one go. That i not want really, I want to upload it to the server from my aspx page in...
5
2660
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 by web method in my Web Form application? I already configurated web.config of my web service by running WSE 3.0 setting tool. Thanks!
0
960
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 anticipation Regards, Nayak
5
1963
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 Delimited/Carriage Return String? Through a file? Other?
2
16130
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 to server and sometimes not, because connection betwenn client and server closed Abrupt. I cannot understand why connection between client and...
0
7462
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7730
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7975
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7492
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5101
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3510
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3491
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1069
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.