On Mon, August 22, 2005 12:30 pm, Evert | Rooftop wrote: > I want to use a PHP script to pass through a file to the browser [ > right > after some processing ]. > What is the fastest way to do this? I know > echo(file_get_contents('myfile')); is not a good idea ;) Actually, it's a Fine Idea *IF* the files are relatively small. Except you don't need parens for "echo" since "echo" is not a function, it's a language construct. echo file_get_contents('myfile'); The extra parens you have are basically order of operation: $x = (2 + 3) * 4 versus $x = 2 + 3 * 4 so you've told PHP to do file_get_contents() FIRST and then, err, there isn't anything else to do, really, so it's kinda silly... Like: $x = (2 + 3); > Is fpassthrough the right choice? Only if you've already opened the file, and you maybe only want to spit out the rest of the file after you skip the first part of the file. > maybe virtual, so it won't go through php but apache does the job? Maybe... But that chews up another HTTP connection, I think... > there's also readfile Slightly better than echo file_get_contents(), but probably not much... > Another question, how seriously does this affect the performance in > comparison to let apache handle it. Is the difference big at MB+ > files? If your files are *HUGE* you probably want to test on YOUR server with fopen/fread-loop. Depending on a bunch of factors, the size of the buffer you choose for fread() could make a difference in the performance, I think. readfile might still be faster, since it's all in C... Or it might not, depending on what buffer size is buried in the C code for readfile. > or only significant when dealing with a lot of tiny files? I suspect that for tiny files, it doesn't make much difference what you use between echo get_file_contents()/readfile or even your own fopen/fread loop. The overhead of the function call and opening up the file, no matter who does it, is going to drawf the actual reading of the contents. TEST ON YOUR OWN SERVER IN LIFE-LIKE ENVIRONMENT That's the only way you'll be sure all the answers here aren't full of [bleep] -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php