Created
November 13, 2012 15:26
-
-
Save taras/4066320 to your computer and use it in GitHub Desktop.
Script that empties Varnish Cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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