Target: To fetch a file using PHP and send to user
Method 1:
echo file_get_conten ts( $file_path );
Method 2:
readfile( $file_path );
Which one is better? 9 21010
On Sep 10, 10:07 am, howa <howac...@gmail .comwrote:
Target: To fetch a file using PHP and send to user
Method 1:
echo file_get_conten ts( $file_path );
Method 2:
readfile( $file_path );
Which one is better?
In practice it probably doesn't make much of a difference. In this
case, however, I'd use readfile since the function was intended to do
exactly what it is that you're trying to do.
howa wrote:
Target: To fetch a file using PHP and send to user
Method 1:
echo file_get_conten ts( $file_path );
Method 2:
readfile( $file_path );
Which one is better?
According to www.php.net:
file_get_conten ts() is the preferred way to read the contents of a file
into a string. It will use memory mapping techniques if supported by
your OS to enhance performance.
But that aside, I don't know what is better.
You could try to see if a huge file give better performance with
file_get_conten ts(), but I expect the networktraffic is a much bigger
concern than the servers file-IO.
Regards,
Erwin Moller
On 9 10 , 10 20 , ZeldorBlat <zeldorb...@gma il.comwrote:
On Sep 10, 10:07 am, howa <howac...@gmail .comwrote:
Target: To fetch a file using PHP and send to user
Method 1:
echo file_get_conten ts( $file_path );
Method 2:
readfile( $file_path );
Which one is better?
In practice it probably doesn't make much of a difference. In this
case, however, I'd use readfile since the function was intended to do
exactly what it is that you're trying to do.
from the doc it said:
file_get_conten ts() is the preferred way to read the contents of a
file into a string
also, readfile() also need to read the entrie file into memory before
send to buffer, so I am just wondering which is better.
On 10.09.2007 16:23 howa wrote:
On 9 10 , 10 20 , ZeldorBlat <zeldorb...@gma il.comwrote:
>On Sep 10, 10:07 am, howa <howac...@gmail .comwrote:
>>Target: To fetch a file using PHP and send to user Method 1: echo file_get_conten ts( $file_path ); Method 2: readfile( $file_path ); Which one is better?
In practice it probably doesn't make much of a difference. In this case, however, I'd use readfile since the function was intended to do exactly what it is that you're trying to do.
from the doc it said:
file_get_conten ts() is the preferred way to read the contents of a
file into a string
also, readfile() also need to read the entrie file into memory before
send to buffer, so I am just wondering which is better.
Actually, readfile doesn't read the whole file, it uses mmap if
possible, otherwise reads/writes in 8K chunks, thus conserving memory.
--
gosha bine
makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
howa <ho******@gmail .comwrote in news:1189441552 .210767.228350
@r29g2000hsg.go oglegroups.com:
>>"readfile" has a knack for ending the file streaming
early on large files
not really understand your point....
i think beside memory limiation, a single call to readfile should be
more efficient.
try streaming a 12MB file, regardless of your memory settings, to
understand my point. your download will end early and you will not get the
complete file.
the function is posted on the manual page for a reason, i personally have
found it vital, use at your discretion.
okay. i get your point.
my files only will have Max 1MB or 2MB...
if file ending early regardless the memory limit, then this should a
bug...
On 9 11 , 12 36 , Good Man <he...@letsgo.c omwrote:
howa <howac...@gmail .comwrote in news:1189441552 .210767.228350
@r29g2000hsg.go oglegroups.com:
>"readfile" has a knack for ending the file streaming
early on large files
not really understand your point....
i think beside memory limiation, a single call to readfile should be
more efficient.
try streaming a 12MB file, regardless of your memory settings, to
understand my point. your download will end early and you will not get the
complete file.
the function is posted on the manual page for a reason, i personally have
found it vital, use at your discretion.
..oO(Good Man)
>try streaming a 12MB file, regardless of your memory settings, to understand my point. your download will end early and you will not get the complete file.
I did a test with a 179MB(!) file on my local server - no problems with
a plain readfile(). Memory limit is set to 32MB, PHP 5.2.3. Script
execution and file delivery took about 70s, memory usage was just 1.7MB.
>the function is posted on the manual page for a reason, i personally have found it vital, use at your discretion.
Maybe a bug in an older version? The UCN is from 2005.
Micha
Michael Fesser <ne*****@gmx.de wrote in
news:e8******** *************** *********@4ax.c om:
.oO(Good Man)
>>try streaming a 12MB file, regardless of your memory settings, to understand my point. your download will end early and you will not get the complete file.
I did a test with a 179MB(!) file on my local server - no problems
with a plain readfile(). Memory limit is set to 32MB, PHP 5.2.3.
Script execution and file delivery took about 70s, memory usage was
just 1.7MB.
>>the function is posted on the manual page for a reason, i personally have found it vital, use at your discretion.
Maybe a bug in an older version? The UCN is from 2005.
Interesting, thanks... as I said, it's not like I used that function right
away, I had to resort to it because my files were getting cut off.
I'll skip it on new coding projects and use plain ol' readfile()
:)
"Good Man" <he***@letsgo.c omwrote in message
news:Xn******** *************** *@216.196.97.13 1...
Michael Fesser <ne*****@gmx.de wrote in
news:e8******** *************** *********@4ax.c om:
>.oO(Good Man)
>>>try streaming a 12MB file, regardless of your memory settings, to understand my point. your download will end early and you will not get the complete file.
I did a test with a 179MB(!) file on my local server - no problems with a plain readfile(). Memory limit is set to 32MB, PHP 5.2.3. Script execution and file delivery took about 70s, memory usage was just 1.7MB.
>>>the function is posted on the manual page for a reason, i personally have found it vital, use at your discretion.
Maybe a bug in an older version? The UCN is from 2005.
Interesting, thanks... as I said, it's not like I used that function right
away, I had to resort to it because my files were getting cut off.
I'll skip it on new coding projects and use plain ol' readfile()
or plain ol' file_get_conten ts()
;^) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Yannick Bétemps |
last post by:
Hi all,
As says the topic, I recently encountered problems with customers using
one of my file management applications and being protected in the same
time with Norton Internet Security firewall.
When the Security is not activated, downloading files works fine, but as
soon as it is activated they can not download anything bigger than 500kb !
I checked in the source code, and whatever the method to read the file
on the server (readfile,...
|
by: ORC |
last post by:
Shouldn't 'ReadFile' block when timeouts are specified even when running in
overlapped mode or am I wrong ???
Thanks
Ole
|
by: Schorschi |
last post by:
Can't seemd to get ReadFile API to work! Returns invalid handle
error?
===========================================================================
Ok, the visual basic gurus, help!
The following is a diskette class (vb .net) that works find, in that I
can validate a diskette is mounted, dismount it, lock it, unlock it,
get diskette geometry, etc., all with a valid handle from CreateFile
API! I can even position the file pointer,...
|
by: jjainschigg |
last post by:
I'm running PHP 5 on a shared VPS. I have a couple little apps that are using file_get_contents() and readfile() for various kinds of (what should be) low-overhead, fast outbound accesses ... that is, I'm handing URLencoded arguments to a couple fast servers and grabbing small patches of XML in return.
When I enter these URL+argument strings in a browser (with the caches turned off), I get effectively instant responses -- so the remote...
|
by: howa |
last post by:
are there any advantage in replacing all fread() operations with
file_get_contents() ?
i.e.
file_get_contents("/usr/local/something.txt")
VS
$filename = "/usr/local/something.txt";
| |
by: Eric Renken |
last post by:
I am trying to do an Overlapped ReadFile on a HID device and it just isn't
working for me. The WaitForSingleObject keeps giving me an error "The
system cannot find the file specified."
This code need to work in 64bit and 32bit, so I am using IntPtr for pointers
instead of int.
Here is the structure of OVERLAPPED
public struct OVERLAPPED
|
by: Taras_96 |
last post by:
Hi everyone,
The output of
echo file_get_contents("http://watchout4snakes.com/creativitytools/
RandomWord/RandomWordPlus.aspx");
leaves the browser empty.. no error messages, nothing.
Why is this occurring?
|
by: pac1250 |
last post by:
Hi,
I am searching how to solve a problem and I dont find it :(
I want to access a page from a script behind a proxy :
(my script) <-(a proxy with authentification) <-(https serveur
with authentification)
-----------------------------------------------------------------
|
by: Ketchup |
last post by:
Hello everyone,
I have been stuck with this problem for quite some time now. I am working in VB.NET, using framework 1.0. I have to keep the compatibility down to the original .NET framework as much as possible. I am forced to use API calls for several functions, one of which is ReadFile. The reason is because the framework seems to use ANSI versions of all API functions, limiting the MAX_PATH for filenames to about 260 chars for ...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |