$urls = $_POST['urls'];

$urls = explode("\n", $urls);
foreach($urls as $reurls){
 $purge_urls[] = trim($reurls);
}

$squid_servers = array('183.61.182.1','121.12.116.20','58.221.59.8');

function purge_cache($server,$url){
 $fp = @fsockopen($server, 80, $errono, $errstr, 3);

 if (!$fp){
  echo $errstr."(".$errno.")";
 }else{
  $head = "purge $url HTTP/1.0\r\n";
  $head .= "Connection: Close\r\n\r\n";

  //echo $head."
";

  fwrite($fp, $head);

  while (!feof($fp)){
   $res = fread($fp, 1024);
   $reb = explode("\r\n", $res);
  
/*   foreach($reb as $n){
    echo $n."
";
   }*/
  
   if(strpos($reb[0], "200") and !empty($reb[0])){
    echo $url." Status:200 Ok!
";
   }elseif(strpos($reb[0], "403") and !empty($reb[0])){
    echo $url." Status:403 Prohibition!
";
   }elseif(strpos($reb[0], "404") and !empty($reb[0])){
    echo $url." Status:404 Not found!
";
   }
  }
  fclose($fp);
 }
}

if($_POST['submit'] == "tijiao"){
 foreach($squid_servers as $server){
   echo $server;
  foreach($purge_urls as $url){
   echo purge_cache($server,$url);
  }
 }
}
?>