Home > php教程 > php手册 > body text

PHP 清空varnish 缓存的详解(包括指定站点下的)

WBOY
Release: 2016-06-06 20:30:12
Original
1173 people have browsed it

本篇文章是对清空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;
}
}
}
?>


需要注意的是:传入进来的 url是不能带参数的  如:?tn=sougou
因为 purge.url 后清空的是 正则表达式 可以改成 (.?)sougou 这样就可以了。

当一台varnish 缓存多个站点内容需要清除指定站点URL 或者单纯清除 站点首页时 需使用purge 而不是purge.url

复制代码 代码如下:


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;
}
}


,香港服务器,网站空间,网站空间
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template