PHP Empties varnish cache details of includes under the specified site
- 2020-06-15 07:54:25
- OfStack
There is no way to clear the contents of the folder, only the specified link cache
It is important to note that the incoming url is not parameterized: www.baidu.com /? tn = sougou
purge. url is a regular expression that can be changed to www. baidu. com/(.?) sougou this will do.
Use purge instead of ES21en.url when one varnish caches multiple sites and needs to clear URL or simply clear the first page of the site
<?php
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;
}
}
}
?>
It is important to note that the incoming url is not parameterized: www.baidu.com /? tn = sougou
purge. url is a regular expression that can be changed to www. baidu. com/(.?) sougou this will do.
Use purge instead of ES21en.url when one varnish caches multiple sites and needs to clear URL or simply clear the first page of the site
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;
}
}