tags:

views:

78

answers:

2

I have noticed that files delivered by PHP through readfile or fpassthru techniques are never cached by the browser.

How can I "encourage" browsers to cache items delivered via these methods?

+2  A: 

Whether your content is cached or not has nothing to do with readfile() and consorts, but probably the default caching headers issued by the server (that would activate caching for HTML pages and image resources) don't apply when you use PHP to pass through files.

You will have to send the appropriate headers along with your content, telling the browser that caching for this resource is all right.

See for example

Caching tutorial for Web Authors and Webmasters

How to use HTTP cache headers with PHP

Pekka
Thanks for the links Pekka. Good reading on the subject.
Bart
A: 

I ended up finding this page and using it as a starting point for my own implementation. The example code on this page, along with some of the reading Pekka pointed to, was a great springboard for me.

Bart