Skip to content

Instantly share code, notes, and snippets.

@taras
Created November 13, 2012 15:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taras/4066320 to your computer and use it in GitHub Desktop.
Save taras/4066320 to your computer and use it in GitHub Desktop.
Script that empties Varnish Cache
# get param
$url = $_POST["url"];
$host = $_POST["host"];
$ip = "127.0.0.1";
$port = "80";
$timeout = 1;
$verbose = 1;
# inits
$sock = fsockopen ($ip,$port,$errno, $errstr,$timeout);
if (!$sock) { echo "connections failed $errno $errstr"; exit; }
if ( !($url || $host) ) { echo "No params"; exit; }
stream_set_timeout($sock,$timeout);
$pcommand = "purge";
# Send command
$pcommand .= ".hash $url#$host#";
put ($pcommand);
put ("quit");
fclose ($sock);
function readit() {
global $sock,$verbose;
if (!$verbose) { return; }
while ($sockstr = fgets($sock,1024)) {
$str .= "rcv: " . $sockstr . "
";
}
if ($verbose) { echo "$str\n"; }
}
function put($str) {
global $sock,$verbose;
fwrite ($sock, $str . "\r\n");
if ($verbose) { echo "send: $str
\n"; }
readit();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment