Reputation: 10583
I am using the following code to PURGE the homepage of a site:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.mysite.com:8080/");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PURGE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 1000);
$r = curl_exec($ch);
echo "<PRE>$r</PRE>";
curl_close($ch);
The response from Varnish is as expected:
HTTP/1.1 200 Purged.
Server: Varnish
Content-Type: text/html; charset=utf-8
Retry-After: 5
Content-Length: 382
Accept-Ranges: bytes
Date: Fri, 10 Aug 2012 10:50:56 GMT
X-Varnish: 617777456
Age: 0
Via: 1.1 varnish
Connection: close
X-Cache: MISS
So now I think that it is purged, but a further call to the page to check the headers suggest that it is not purged. As Age: 15
and X-Cache: HIT
are both set, suggesting that the page is still cached and is 15 seconds old.
The TTL is 120.
Am I missing something?
Thanks Jake
Upvotes: 4
Views: 10287
Reputation: 304
Just to know, PURGE works on the beReq.
If you modify the req.url (i.e. add prefix or a suffix to your URI), you should do the same in the vcl_recv that calls purge. Alternatively, you have to write the purge condition inside the main vcl_recv after the url manipulation.
Upvotes: 1
Reputation: 5952
To eliminate all other php/curl issues I would start with the most basic low-level check.
This works for me:
netcat -C varnish_hostname 80 <<EOF
PURGE /the/url
Host: hostname
EOF
Once you get this to work, you know that your VCL rules and ACLs are not an issue and you may proceed to the curl/php level.
EDIT Two notes:
netcat -C
option is there to convert newlines to CRLF char pairs per the HTTP protocol.Upvotes: 5
Reputation: 851
I think you would not have checked for purging in the default.vcl The default.vcl should contain something like following:
acl purge {
"localhost";
"192.168.55.0"/24;
}
sub vcl_recv {
# allow PURGE from localhost and 192.168.55...
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
}
return (lookup);
}
}
sub vcl_hit {
if (req.request == "PURGE") {
purge;
error 200 "Purged.";
}
}
sub vcl_miss {
if (req.request == "PURGE") {
error 200 "OK but nothing to purge - URL was not in cache";
}
}
Upvotes: 2
Reputation: 885
I wanted to comment that you should post your default.vcl file, but my reputation is too low.
PURGE is implemented in your vcl file (or at least it should if you expect it to work), and what it does and does not is there on code. It could be blocking your PURGE based on the ip address from where you are connecting, or it could be not implemented.
Upvotes: 1