squid php清除缓存(4)

来源:互联网 发布:js给html元素赋值 编辑:程序博客网 时间:2024/06/05 15:42

每次勇telnet清除或者squidclinent清除缓存太麻烦,索性写个php的缓存清理工具!

全部代码如下:

# cat purge.php<title>purge cache</title><div><center><h1>缓存管理</h1></center></div><hr><h3>在以下文本框中输入需要清除缓存的URL:</h3><br>注意:每行一个URL 次输入框在右下角可以拉伸!<form action="" name="form1" id="form1" method="post"><select name="downlist" >      <option value="01" selected="selected" >要清除的服务器1</option>      <option value="02">要清除的服务器2</option>    </select><br>    <td><label><textarea name="nr" cols="50" rows="10"></textarea></label></td>      <input type="submit" name="submit" id="submit" value="PUGRE"></form><?php@$nr = $_POST['nr'];$path = explode("\r\n",$nr);$i = 0;while($path[$i] != ""){$i++;}@$selct=$_POST['downlist'];switch($selct)           {             case "01":                $host = "要清除的服务器1的ip";              break;             case "02":               $host = "要清除的服务器2的ip";         }define("SQUID_PORT"             , "80");function purge_file($squid_host,$squid_port,$file_url) {        $result = array();        for ($i = 0; $i<=1; $i++) {                $fp = fsockopen($squid_host,$squid_port,$errno,$errstr,5);                if (!$fp) {                        echo "$errstr ($errno)<br />\n";                } else {                        $header = "purge $file_url HTTP/1.0\r\n";                        $header .= "Connection: Close\r\n\r\n";                        fwrite($fp, $header);                        $result[$i] = fgets($fp) . "<br/>";                        fclose($fp);                }        }        return($result);}$reset = "";for ($y=0; $y<$i; $y++) {                $url = $path[$y];                $res = purge_file($host,SQUID_PORT,$url);                if ($res) {                        $result_1 = explode(" ", $res['0']);                        $result_2 = explode(" ", $res['1']);                        if ($result_1['1'] == 404) {                                $reset = "地址:$url <td>未被缓存!</td>(404)";                        } elseif ($result_1['1'] == 200 && $result_2['1'] == 404) {                                $reset = "地址:$url <td>已经刷新!</td>(200)";                        } elseif ($result_1['1'] == 403) {                                $reset = "请求被拒绝,刷新缓存acl没有被allow!";                        }                } else {                        $reset = "连接到cache服务器:" . SQUID_HOST . ",retry!";                }print $reset;print "<br>";}?>


#######################################################

迷途小运维原创

作者:john

转载请注明出处


0 0
原创粉丝点击