{"id":2074,"date":"2011-09-05T17:56:01","date_gmt":"2011-09-05T10:56:01","guid":{"rendered":"http:\/\/ton.packetlove.com\/blog\/?p=2074"},"modified":"2011-09-05T18:15:51","modified_gmt":"2011-09-05T11:15:51","slug":"php-purge-script-for-varnish-3-xx","status":"publish","type":"post","link":"https:\/\/ton.packetlove.com\/blog\/php\/php-purge-script-for-varnish-3-xx.html","title":{"rendered":"PHP Purge Script for Varnish 3.xx"},"content":{"rendered":"<p>\u0e2a\u0e27\u0e31\u0e2a\u0e14\u0e35\u0e04\u0e23\u0e31\u0e1a \u0e27\u0e31\u0e19\u0e19\u0e35\u0e49 \u0e1e\u0e2d\u0e14\u0e35\u0e1c\u0e21 modify \u0e15\u0e31\u0e27 Purge URL \u0e17\u0e35\u0e48\u0e40\u0e1b\u0e47\u0e19 PHP Script \u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a<br \/>\nVarnish 3.xx \u0e21\u0e32\u0e43\u0e0a\u0e49\u0e07\u0e32\u0e19 \u0e01\u0e47\u0e40\u0e25\u0e22\u0e40\u0e2d\u0e32\u0e21\u0e32\u0e41\u0e1a\u0e48\u0e07\u0e1b\u0e31\u0e19\u0e01\u0e31\u0e19\u0e04\u0e23\u0e31\u0e1a \u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a\u0e01\u0e32\u0e23\u0e43\u0e0a\u0e49\u0e07\u0e32\u0e19\u0e01\u0e47\u0e04\u0e37\u0e2d<br \/>\n\u0e2a\u0e48\u0e07 Parameter \u0e21\u0e32\u0e41\u0e1a\u0e1a\u0e19\u0e35\u0e49\u0e04\u0e23\u0e31\u0e1a ..<br \/>\nvpurge.php?url=\/xxx.html&amp;host=test.com<\/p>\n<p>vpurge.php<\/p>\n<pre escaped=\"true\" lang=\"php\" line=\"1\">\r\n\r\n# get param\r\n$url = $_GET[\"url\"];\r\n$host = $_GET[\"host\"];\r\n\r\n  # Varnish 3.xx IP\r\n  $ip = \"127.0.0.1\";\r\n  # T port\r\n  $port = \"6082\";\r\n\r\n  $timeout = 1;\r\n  $verbose = 1;\r\n\r\n  # inits\r\n  $sock = fsockopen ($ip,$port,$errno, $errstr,$timeout);\r\n  if (!$sock) { echo \"connections failed $errno $errstr\"; exit; }\r\n\r\n  if ( !($url || $host) ) { echo \"No params\"; exit; }\r\n\r\n  stream_set_timeout($sock,$timeout);\r\n\r\n  #$pcommand = \"purge\";\r\n  # Send command\r\n  #$pcommand .= \".hash $url#$host#\";\r\n\r\n  ### PHP Purge for Varnish 3.xx      ###\r\n  ### Modify by: Ton 2011-09-05       ###\r\n  ### http:\/\/ton.packetlove.com\/blog\/ ###\r\n  $pcommand = \"ban\";\r\n  $pcommand .= \" req.http.host == $host && req.url ~ ^$url.*$\";\r\n\r\n  put ($pcommand);\r\n  put (\"quit\");\r\n\r\n  fclose ($sock);\r\n\r\n  function readit() {\r\n    global $sock,$verbose;\r\n    if (!$verbose) { return; }\r\n    while ($sockstr = fgets($sock,1024)) {\r\n      $str .= \"rcv: \" . $sockstr . \"<br>\";\r\n    }\r\n    if ($verbose) { echo \"$str\\n\"; }\r\n  }\r\n\r\n  function put($str) {\r\n    global $sock,$verbose;\r\n    fwrite ($sock, $str . \"\\r\\n\");\r\n    if ($verbose) { echo \"send: $str <br>\\n\"; }\r\n\treadit();\r\n  }\r\n\r\n<\/pre>\n<p>\u0e07\u0e48\u0e32\u0e22\u0e46 \u0e40\u0e1e\u0e35\u0e22\u0e07\u0e40\u0e17\u0e48\u0e32\u0e19\u0e35\u0e49 \u0e41\u0e04\u0e48\u0e40\u0e23\u0e32\u0e2a\u0e48\u0e07 parameter \u0e21\u0e32\u0e01\u0e47\u0e17\u0e33\u0e01\u0e32\u0e23 purge URL \u0e17\u0e35\u0e48\u0e15\u0e49\u0e2d\u0e07\u0e01\u0e32\u0e23\u0e44\u0e14\u0e49\u0e41\u0e25\u0e49\u0e27\u0e04\u0e23\u0e31\u0e1a \ud83d\ude42<\/p>\n<div class=\"fcbkbttn_buttons_block\" id=\"fcbkbttn_left\"><div class=\"fcbkbttn_like \"><fb:like href=\"https:\/\/ton.packetlove.com\/blog\/php\/php-purge-script-for-varnish-3-xx.html\" action=\"like\" colorscheme=\"light\" layout=\"button_count\"  size=\"small\"><\/fb:like><\/div><div class=\"fb-share-button  \" data-href=\"https:\/\/ton.packetlove.com\/blog\/php\/php-purge-script-for-varnish-3-xx.html\" data-type=\"button_count\" data-size=\"small\"><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>\u0e2a\u0e27\u0e31\u0e2a\u0e14\u0e35\u0e04\u0e23\u0e31\u0e1a \u0e27\u0e31\u0e19\u0e19\u0e35\u0e49 \u0e1e\u0e2d\u0e14\u0e35\u0e1c\u0e21 modify \u0e15\u0e31\u0e27 Purge URL \u0e17\u0e35\u0e48\u0e40\u0e1b\u0e47\u0e19 PHP Script \u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a Varnish 3.xx \u0e21\u0e32\u0e43\u0e0a\u0e49\u0e07\u0e32\u0e19 \u0e01\u0e47\u0e40\u0e25\u0e22\u0e40\u0e2d\u0e32\u0e21\u0e32\u0e41\u0e1a\u0e48\u0e07\u0e1b\u0e31\u0e19\u0e01\u0e31\u0e19\u0e04\u0e23\u0e31\u0e1a \u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a\u0e01\u0e32\u0e23\u0e43\u0e0a\u0e49\u0e07\u0e32\u0e19\u0e01\u0e47\u0e04\u0e37\u0e2d \u0e2a\u0e48\u0e07 Parameter \u0e21\u0e32\u0e41\u0e1a\u0e1a\u0e19\u0e35\u0e49\u0e04\u0e23\u0e31\u0e1a .. vpurge.php?url=\/xxx.html&amp;host=test.com vpurge.php # get param $url = $_GET[&#8220;url&#8221;]; $host = $_GET[&#8220;host&#8221;]; # Varnish 3.xx IP $ip = &#8220;127.0.0.1&#8221;; # T port $port = &#8220;6082&#8221;; $timeout = 1; $verbose = 1; # inits $sock = fsockopen [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,18],"tags":[847,848,846],"class_list":["post-2074","post","type-post","status-publish","format-standard","hentry","category-php","category-tuning","tag-php-purge-varnish","tag-varnish-3-purge","tag-varnish-purge"],"_links":{"self":[{"href":"https:\/\/ton.packetlove.com\/blog\/wp-json\/wp\/v2\/posts\/2074","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ton.packetlove.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ton.packetlove.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ton.packetlove.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ton.packetlove.com\/blog\/wp-json\/wp\/v2\/comments?post=2074"}],"version-history":[{"count":14,"href":"https:\/\/ton.packetlove.com\/blog\/wp-json\/wp\/v2\/posts\/2074\/revisions"}],"predecessor-version":[{"id":2088,"href":"https:\/\/ton.packetlove.com\/blog\/wp-json\/wp\/v2\/posts\/2074\/revisions\/2088"}],"wp:attachment":[{"href":"https:\/\/ton.packetlove.com\/blog\/wp-json\/wp\/v2\/media?parent=2074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ton.packetlove.com\/blog\/wp-json\/wp\/v2\/categories?post=2074"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ton.packetlove.com\/blog\/wp-json\/wp\/v2\/tags?post=2074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}