Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

caching headers from PHP

In PHP, by default no cache related headers are sent.

HTTP/1.1 200 OK
Date: Fri, 19 Nov 2010 11:02:16 GMT
Server: Apache/2.2.15 (Win32) PHP/5.2.9-2
X-Powered-By: PHP/5.2.9-2
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 26
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html

Now, since by default it does not say anything about caching, can it result in say example.com/index.php getting cached in some situations?

like image 999
Sabya Avatar asked Jan 25 '26 05:01

Sabya


2 Answers

Yes. In general, every successful response may be cached unless there are some constrains:

Unless specifically constrained by a cache-control (section 14.9) directive, a caching system MAY always store a successful response (see section 13.8) as a cache entry, MAY return it without validation if it is fresh, and MAY return it after successful validation.

like image 180
Gumbo Avatar answered Jan 27 '26 19:01

Gumbo


Yes, usually the browser will cache certain files by default (usually images and css) if no rules have been setup on the server-side (see browser cache).

You can set up cache-control headers to control this, or disable it completely using:

header("Cache-Control: no-store, no-cache, must-revalidate"); 
header("Cache-Control: post-check=0, pre-check=0", false); 
header("Pragma: no-cache");

See example #2 in header and read the note below it.

like image 26
fire Avatar answered Jan 27 '26 20:01

fire