Home > Backend Development > PHP Tutorial > Detailed explanation of clearing Varnish cache in PHP (including those under specified sites)_PHP Tutorial

Detailed explanation of clearing Varnish cache in PHP (including those under specified sites)_PHP Tutorial

WBOY
Release: 2016-07-21 15:05:12
Original
922 people have browsed it

There is no way to clear the folder contents. You can only clear the specified link cache

Copy code The code is as follows:

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; s( $fp , 4096);
fclose ($fp);
return $out;
}
}
}
?>




It should be noted that:

The incoming url cannot take parameters, such as: www.baidu.com/?tn=sougouBecause purge.url is cleared after regular rules The expression can be changed to www.baidu.com/(.?)sougou and that's it. When a varnish caches the content of multiple sites and needs to clear the specified site URL or simply clear the site homepage, purge must be used instead of purge.url


Copy code
The code is as follows: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 ~ ^/$ rn";
                                                                                           " purge.url {$url} rn";
                                                                                                                     close ($fp);
             return $out;                                                            



http://www.bkjia.com/PHPjc/327716.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/327716.html
TechArticle
Unable to clear the folder contents, you can only clear the specified link cache. Copy the code as follows: ?php function clearVarnish($ip ,$url,$host=null){ $errstr = ''; $errno = ''; $varnist_arr = isse...

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template