Jak*_*e N 4 php caching varnish
我正在使用以下代码清除网站的主页:
$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);
Run Code Online (Sandbox Code Playgroud)
Varnish 的响应符合预期:
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
Run Code Online (Sandbox Code Playgroud)
所以现在我认为它被清除了,但是进一步调用页面以检查标题表明它没有被清除。AsAge: 15和X-Cache: HIT都设置了,这表明该页面仍在缓存中并且已经存在 15 秒。
TTL 为 120。
我错过了什么吗?
谢谢杰克
为了消除所有其他 php/curl 问题,我将从最基本的低级检查开始。
这对我有用:
netcat -C varnish_hostname 80 <<EOF
PURGE /the/url
Host: hostname
EOF
Run Code Online (Sandbox Code Playgroud)
一旦你让它工作,你就知道你的 VCL 规则和 ACL 不是问题,你可以继续到 curl/php 级别。
编辑两个注释:
netcat -C选择是有转换换行符每HTTP协议CRLF炭对。