PHP100 2019-03-27
代码如下:
<?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; } } } ?>
代码如下:
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; } }