How to purge the cache by HTTP

Ajian ajian521 at gmail.com
Mon Mar 2 08:23:29 CET 2009


     The problem is about how to purge the cache by the http.
    When my hash is the fellow ,I can solve it

   sub vcl_hash {
   set req.hash += req.url;
   hash;
}

   I have write a php file to purge the cache

  <?php
       function purge($ip, $domain, $url)
       {
       $errstr = '';
       $errno = '';
       $fp = fsockopen ($ip, 80, $errno, $errstr, 2);
       if (!$fp)
       {
       return false;
       }
       else
       {
       $out = "PURGE $url HTTP/1.1\r\n";
       $out .= "Host:$domain\r\n";
       $out .= "Connection: close\r\n\r\n";
       fputs ($fp, $out);
       $out = fgets($fp , 4096);
       echo $out;
       fclose ($fp);
       return true;
       }
       }

       $domain = $_GET['a'];
       $imgurl = $_GET['b'];

       $squid = array(
       '221.238.196.199',
       '221.238.196.200',
       );

       foreach($squid as $ip)
       {
       if(!empty($ip))
       {
       purge($ip, $domain, $imgurl);
       echo "clear is over";
       }
       }

 ?>

But, I change the hash, use the similar way but can't clear it ,output
"HTTP/1.1 404 Not in cache "

sub vcl_hash {
   set req.hash += req.url;
    if (req.http.Accept-Encoding) {
       set req.hash += req.http.Accept-Encoding;
   }
   hash;
}


I have try use

$out = "PURGE $url HTTP/1.1\r\n";
       $out .= "Host:$domain\r\n";
       $out .= "Accept-Encoding:gzip,deflate\r\n";
       $out .= "Connection: close\r\n\r\n";
       fputs ($fp, $out);

and $out .= "Accept-Encoding:gzip\r\n";

$out .= "Accept-Encoding:deflate\r\n";

Without success.

who can tell me how to purge the hash cache ,how to write the php ,I need
through remote empty cache ,thanks.

I hope you can understand what I mean, my English is pool.


Ajian
====================================================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20090302/f90ef0bd/attachment-0002.html>


More information about the varnish-misc mailing list