本篇文章是对清空varnish的缓存(包括指定站点下的)进行了详细的分析介绍,需要的朋友参考下
没法清空文件夹内容 只能清空指定链接缓存
复制代码 代码如下:
function clearVarnish($ip,$url,$host=null){
$errstr = '';
$errno = '';
$varnist_arr = isset($host) ? $host : C('VARNISH_LIST');
foreach ($varnist_arr as $v){
$fp = fsockopen ($ip, 2000, $errno, $errstr, 2);
if (!$fp) {
return false;
} else {
$out = "purge.url $url \r\n";
fputs ($fp, $out);
$out = fgets($fp , 4096);
fclose ($fp);
return $out;
}
}
}
?>
复制代码 代码如下:
function varnish_purge($ip, $host='', $url) {
$errstr = '';
$errno = '';
$fp = fsockopen ($ip, 2000, $errno, $errstr, 2);
if (!$fp) {
return $errno;
}else {
if(!empty($host)){
$out = "purge req.http.host == {$host} && req.url ~ ^/$ \r\n";
}else{
$out = " purge.url {$url} \r\n";
}
fputs ($fp, $out);
$out = fgets($fp , 4096);
fclose ($fp);
return $out;
}
}