Reputation: 933
I'm trying the understand local cache with ETags and a nginx (1.2.1) server which redirects php's request to a php-cgi deamon.
Here my simple index.php :
<?php
header('Cache-Control: public');
header('Etag:"5954c6-10f4-449d11713aac0"');
echo microtime(true);
After a second request, my browser send a If-None-Match header :
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
Host:cache.loc
If-None-Match:"5954c6-10f4-449d11713aac0"
But my web server doesn't returns a 304 :
HTTP/1.1 200 OK
Server: nginx/1.2.2
Date: Thu, 12 Jul 2012 11:46:03 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.3.12
Cache-Control: public
Etag: "5954c6-10f4-449d11713aac0"
Cache-Control: public
Unless I've misunderstood, my server should compare Etag with the If-None-Match sent and returns a 304 response because they're the same.
Where am I wrong ? Should I compare Etag with If-None-Match in my PHP script because nginx (or Apache) will not do the job itself ?
Regards, Manu
Upvotes: 2
Views: 3920
Reputation: 99851
If you implement this yourself using php, you are responsible for also sending the 304 Not Modified.
So compare the If-None-Match header with your ETag, and use header() to send back the 304.
Upvotes: 3