473,325 Members | 2,816 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,325 software developers and data experts.

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

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

Similar topics

2
by: Stijn Goris | last post by:
Hi all, I have a question regarding the header function. I send a browser to a certain page (eg first.php ) wich sends no output to the browser. This page sends the browser to another page (eg...
11
by: Francisco Mendez | last post by:
I get the following message when trying to run my script: "Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/newcustomer.php:23) in...
13
by: Dave Smithz | last post by:
Hi there, I have a php script that does some form input validation. As it verifies each field if the field has incorrect data, it appends an error message to an $error array. E.g. if...
23
by: lwoods | last post by:
I am trying to pass some info to another page on my site. I set "session_start()" in page 1, assign a session variable to a value, then execute a "header('Location: ....')." But on the target...
16
by: a | last post by:
Hi everybody, My config: Win XP (or 2003), Apache 2.0.54, PHP 5.1.2. I have been trying to handle the case of a lenghty opearation on the server while providing the user with feedback and...
5
by: Duderino82 | last post by:
I'm working on a very simple peace of php where basically there is a form and 3 buttoms. One refreshed the page, one posts the form, and another one (since this form contains values of a record)...
10
by: universalbitmapper | last post by:
Hi, I'm trying a simple form.html that call a .html script that begins with: <?php header("This is a test"); ?> When I click on the link, I get blank page.
3
by: thomasg | last post by:
Hi, I am moving some scripts from a UNIX box to a Windows box. A data entry form calls a PHP script the updates the records from the form. After the script completes, The script redirects to...
6
by: webgenius | last post by:
I'm designing a small site and I have this structure in mind: index.php --------------- login fields. User enters login info. LoginCheck.php is called. LoginCheck.php -----------------------...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.