巧用trafficserver (ATS)的PUSH功能来主动更新cache
贵贵的博客 ( http://blog.linuxphp.org/ ) :
1.修改ip_allow.config打开push功能支持
2.修改records.config修改
CONFIG proxy.config.http.push_method_enabled INT 1
3.traffic_ctl config reload重新加载配置
4.代码示例
<?php // 要缓存的URL $url = "http://test.cn/test2.html"; $parse = parse_url($url); // ats port $host = "test.cn"; $port = 8081; $fp = fsockopen($host, $port, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { // html正文 $html = " <HTML> ab </HTML> "; // 要缓存的地址被请求返回的头信息 $responseHeader = "HTTP/1.0 200 OK\r\n"; $responseHeader .= "Content-type: text/html\r\n"; $responseHeader .= "Content-length: " . strlen($html)."\r\n\r\n"; // 发送给ATS的push头 $pushLen = strlen($responseHeader . $html); $pushHeader = "PUSH $url HTTP/1.0\r\n"; $pushHeader .= "Content-length: $pushLen\r\n\r\n"; fwrite($fp, $pushHeader); fwrite($fp, $responseHeader); fwrite($fp, $html); // ATS返回信息,如果返回200或201则成功 while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } ?>
文章来源:
Author:linuxphp@qq.com(keminar)
link:http://blog.linuxphp.org/archives/1643/