PHP clears the varnish cache (including files on the specified site ). You cannot clear the folder content. you can only clear the specified link cache. copy the code as follows :? PhpfunctionclearVarnish ($ ip, $ url, $ hostnull) {$ errstr; $ errno; $ varnist_arrisse cannot clear folder content but can only clear the specified link cache
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;
} Else {
$ Out = "purge. url $ url \ r \ n ";
Fputs ($ fp, $ out );
$ Out = fgets ($ fp, 4096 );
Fclose ($ fp );
Return $ out;
}
}
}
?>
Note that:The entered url does not contain parameters such as www.baidu.com /? Tn = sougou
Because after purge. url is cleared, the regular expression can be changed to www.baidu.com /(.?) Sougou.
When one varnish caches multiple sites, you need to clear the specified site URL or simply clear the site homepage, you need to use purge instead of purge. url.
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 ~ ^/$ \ R \ n ";
} Else {
$ Out = "purge. url {$ url} \ r \ n ";
}
Fputs ($ fp, $ out );
$ Out = fgets ($ fp, 4096 );
Fclose ($ fp );
Return $ out;
}
}
The following code can only be used to clear the specified link cache :? Php function clearVarnish ($ ip, $ url, $ host = null) {$ errstr = ''; $ errno =''; $ varnist_arr = isse...