By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 1,852 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

what is better : readfile, fpassthru, or header(" Location: ...")?

P: n/a
Hello,
I need to display or propose a jpeg image on a web page.

When I need to display the image, I use this code :
header("Content-Length: $fileSize") ;
header("Content-Type: $type") ;
header("Content-disposition: inline") ;
header("Location: $imageURL");

And when I need to propose the image to save, I use this one :
header("Content-Length: $fileSize") ;
header("Content-Type: $type") ;
header("Content-disposition: attachment; filename=\"$fileName\"") ;
header("Location: $imageURL");

Everything is working fine, but now, I also need to hide the real path ofthe
image on the server.

So instead of the header(Location: ...), I can use readfile, and this work.
But I'm not sur that is a good solution for a website, if I need to serve
multiple jpeg files of 4~5 Mb each...

My questions are :

- Is the readfile cpu consumption is really more important than serving
directly the image url with apache ?
- Is there a limit in php with the number of readfile calls, like number of
file pointers opened by fopen() ?

What is the difference with readfile and fpassthru ?

Thanks.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGpebxN5PdEh7mYkIRAufhAJ0d/AB+5cWA4K+HQyA/4gPg+24rUQCghgS3
cprQ8Li8VE7snNk0mvPl/04=
=INGB
-----END PGP SIGNATURE-----

Jul 24 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
andre rodier wrote:
- Is the readfile cpu consumption is really more important than serving
directly the image url with apache ?
readfile() is pretty efficient. If you are really bothered with
performance you can look at http://tn123.ath.cx/mod_xsendfile/

Jul 24 '07 #2

P: n/a
Thanks a lot for your answer.
--
André Rodier.

Sjoerd wrote:
andre rodier wrote:
>- Is the readfile cpu consumption is really more important than serving
directly the image url with apache ?

readfile() is pretty efficient. If you are really bothered with
performance you can look at http://tn123.ath.cx/mod_xsendfile/
Jul 24 '07 #3

P: n/a
andre rodier wrote:
When I need to display the image, I use this code :
header("Content-Length: $fileSize") ;
header("Content-Type: $type") ;
header("Content-disposition: inline") ;
header("Location: $imageURL");
The "Location" HTTP header just does a redirect, so there's precious
little use in sending any of those other headers first as the web server
will fill them in automatically when the browser requests the target URL.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 33 days, 19:46.]

Parsing an HTML Table with PEAR's XML_HTTPSax3
http://tobyinkster.co.uk/blog/2007/0...table-parsing/
Jul 24 '07 #4

P: n/a
Yeah, in addition to those great options, you also have virtual('/my/
file.jpg').

readfile should be perfectly fine...

On Jul 24, 8:34 am, andre rodier <andrerod...@free.frwrote:
Thanks a lot for your answer.
--
André Rodier.

Sjoerd wrote:
andre rodier wrote:
- Is the readfile cpu consumption is really more important than serving
directly the image url with apache ?
readfile() is pretty efficient. If you are really bothered with
performance you can look athttp://tn123.ath.cx/mod_xsendfile/

Jul 24 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.