Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
litespeed_wiki:litespeed:cache:purge [2015/04/20 18:29]
Serge Espitia
— (current)
Line 1: Line 1:
-====== LSWS Cache PURGE ====== 
  
-===== Summary ===== 
-As of 4.1.12, LSWS supports cache PURGE operation to accommodate the demand on cache manipulation. 
- 
-===== Procedures ===== 
-Here are the steps to PURGE cache: 
- 
- 
- 
- 
- 
- 
-==== Create a wrapper script purge.php for PURGE ==== 
- 
-<​code>​ 
-<?php 
-$fp = fsockopen('​192.168.0.81',​ 80, $errno, $errstr, 2); 
-if (!$fp) { 
-    echo "​$errstr ($errno)\n";​ 
-} else { 
-    $out = "PURGE /hello.php HTTP/​1.0\r\n"​ 
-    . "Host: www.example.com\r\n"​ 
-    //. "​Authorization:​ Basic "​.base64_encode("​userid:​password"​)."​\r\n"​ 
-    . "​Connection:​ Close\r\n\r\n";​ 
-    fwrite($fp, $out); 
-    echo $out; 
-    while (!feof($fp)) { 
-        echo fgets($fp, 128); 
-    } 
-    fclose($fp);​ 
-} 
-?> 
-</​code>​ 
- 
-**Note:​**  ​ 
-  - We are using internal IP address 192.168.0.80 for illustration purposes only. In a real world application,​ make sure that vhost listens on 192.168.0.80 for domain name [[www.example.com]]. 
-  - Authentication can be added to make the PURGE more secure. Comments in the script simplify the process. 
- 
- 
-==== Set up Rewrite Rules to Allow PURGE ==== 
- 
-put the following rules in .htaccess 
- 
-  RewriteEngine On 
-  RewriteCond %{REQUEST_METHOD} ^HEAD|GET|PURGE$ 
-  RewriteCond %{REQUEST_URI} !^/​purge\.php$ 
-  RewriteRule .* - [E=Cache-Control:​max-age=120,​L] 
- 
-**Note:** PURGE needs to be in the allowed method. 
- 
-=== Whitelist source IP to issue PURGE request ==== 
- 
-Admin Console => Configuration => Server => Security => Allow List 
- 
-append Source_IP with tailing '​T'​ for trusted IP like  'ALL, 192.168.0.81T'​ 
- 
- 
- 
-===== Operations ===== 
- 
- 
-==== 1. Create Cache ==== 
- 
- ​1.1 ​ point browser to [[http://​www.example.com/​hello.php]] 
- 
- ​1.2 ​ cache storage has a new file created for hello.php (for illustration,​ we clean cache storage in our lab prior to step 1). 
-<​file>​ 
-[root@cptest diskcache]# ls -lrt */*/* 
-9/c/6: 
-total 12 
--rw------- 1 nobody nobody 11638 May  2 15:42 9c6eae83978ecd87 
- 
-[root@cptest diskcache]# 
-</​file>​ 
- 
-==== 2. Request the same resource from cache ==== 
- 
-  request http://​www.example.com/​hello.php again from browser. receive '​X-Litespeed-Cache:​ hit' response header as a prove  
-<​file>​ 
-   Date: Wed, 02 May 2012 23:59:53 GMT 
-   ​Content-Encoding:​ gzip 
-   ​X-Litespeed-Cache:​ hit   <​=== here it is 
-   ​Connection:​ Keep-Alive 
-   ​Content-Length:​ 10 
-   ​Server:​ LiteSpeed 
-   Vary: Accept-Encoding 
-   ​Content-Type:​ text/html 
-   ​Keep-Alive:​ timeout=5, max=100 
-</​file>​ 
- 
- 
- 
-==== 3. Issue purge request from server ==== 
- 
- 3.1 1st time, '200 Purged'​ status returned. 
-<​file>​ 
-   ​[test@test ~]$ php purge.php 
-   PURGE /hello.php HTTP/1.0 
-   Host: www.example.com 
-   ​Connection:​ Close 
- 
-   ​HTTP/​1.0 200 Purged 
-   Date: Wed, 02 May 2012 23:48:23 GMT 
-   ​Server:​ LiteSpeed 
-   ​Connection:​ close 
- 
-   ​[test@test ~]$  
-</​file>​ 
- 
-**Note:** '​HTTP/​1.0 200 Purged'​ indicates the resource is purged. 
- 
-Rewrite Log shown  
-<​file>​ 
-2012-05-02 15:​43:​20.280 [INFO] [192.168.0.81:​60174-0#​APVH_lstest.com] [REWRITE] strip base: '/'​ from URI: '/​phpinfo.php'​ 
-2012-05-02 15:​43:​20.280 [INFO] [192.168.0.81:​60174-0#​APVH_lstest.com] [REWRITE] Rule: Match '​phpinfo.php'​ with pattern '​.*',​ result: ​ 
-1 
-2012-05-02 15:​43:​20.280 [INFO] [192.168.0.81:​60174-0#​APVH_lstest.com] [REWRITE] Cond: Match '​PURGE'​ with pattern '​^HEAD|GET|PURGE$', ​ 
-result: 1 
-2012-05-02 15:​43:​20.280 [INFO] [192.168.0.81:​60174-0#​APVH_lstest.com] [REWRITE] Cond: Match '/​phpinfo.php'​ with pattern '​^/​purge\.php 
-$', result: -1 
-2012-05-02 15:​43:​20.280 [INFO] [192.168.0.81:​60174-0#​APVH_lstest.com] [REWRITE] apply cache-control:​ '​max-age=120'​. 
-2012-05-02 15:​43:​20.280 [INFO] [192.168.0.81:​60174-0#​APVH_lstest.com] [REWRITE] No substition 
-2012-05-02 15:​43:​20.280 [INFO] [192.168.0.81:​60174-0#​APVH_lstest.com] [REWRITE] Last Rule, stop! 
-2012-05-02 15:​43:​20.281 [NOTICE] [192.168.0.81:​60174-0#​APVH_lstest.com:​cache] [PUBLIC CACHE] PURGE /​phpinfo.php,​ result: 1 
-2012-05-02 15:​43:​20.281 [DEBUG] [192.168.0.81:​60174-0#​APVH_lstest.com:​cache] HttpConnection::​sendHttpError(),​code=200 Purged 
- 
- ... 
- 
-</​file>​ 
- 
- 3.2 2nd purge request results in 405 error 
- 
-<​file>​ 
-   ​[test@test ~]$ php purge.php 
-   PURGE /hello.php HTTP/1.0 
-   Host: www.lstest.com 
-   ​Connection:​ Close 
- 
-   ​HTTP/​1.0 405 Method Not Allowed 
-   Date: Wed, 02 May 2012 23:37:44 GMT 
-   ​Server:​ LiteSpeed 
-   ​Connection:​ close 
-   ​Cache-Control:​ private, no-cache, max-age=0 
-   ​Pragma:​ no-cache 
-   ​Content-Type:​ text/html 
-   ​Content-Length:​ 383 
- 
-   ​[test@test ~]$ 
-</​file>​ 
- 
-Rewrite Log shown 
-<​file>​ 
-2012-05-02 15:​43:​39.588 [NOTICE] [192.168.0.81:​60175-0#​APVH_lstest.com] Content len: 0, Request line: 'PURGE /​phpinfo.php HTTP/​1.1'​ 
-2012-05-02 15:​43:​39.588 [DEBUG] [192.168.0.81:​60175-0#​APVH_lstest.com] Find context with URI: [/], location: [/​home/​lstestc/​public_html/​] 
-... 
-2012-05-02 15:​43:​39.588 [INFO] [192.168.0.81:​60175-0#​APVH_lstest.com] [REWRITE] strip base: '/'​ from URI: '/​phpinfo.php'​ 
-2012-05-02 15:​43:​39.588 [INFO] [192.168.0.81:​60175-0#​APVH_lstest.com] [REWRITE] Rule: Match '​phpinfo.php'​ with pattern '​.*',​ result: 1 
-2012-05-02 15:​43:​39.588 [INFO] [192.168.0.81:​60175-0#​APVH_lstest.com] [REWRITE] Cond: Match '​PURGE'​ with pattern '​^HEAD|GET|PURGE$',​ result: 1 
-2012-05-02 15:​43:​39.588 [INFO] [192.168.0.81:​60175-0#​APVH_lstest.com] [REWRITE] Cond: Match '/​phpinfo.php'​ with pattern '​^/​purge\.php$',​ result: -1 
-2012-05-02 15:​43:​39.588 [INFO] [192.168.0.81:​60175-0#​APVH_lstest.com] [REWRITE] apply cache-control:​ '​max-age=120'​. 
-2012-05-02 15:​43:​39.588 [INFO] [192.168.0.81:​60175-0#​APVH_lstest.com] [REWRITE] No substition 
-2012-05-02 15:​43:​39.588 [INFO] [192.168.0.81:​60175-0#​APVH_lstest.com] [REWRITE] Last Rule, stop! 
-2012-05-02 15:​43:​39.588 [DEBUG] [192.168.0.81:​60175-0#​APVH_lstest.com] HttpConnection::​sendHttpError(),​code=405 Method Not Allowed 
-2012-05-02 15:​43:​39.588 [DEBUG] [192.168.0.81:​60175-0#​APVH_lstest.com] redirect to:  
-        URI=[/​405.shtml],​ 
-        QueryString=[] 
-</​file>​ 
- 
-==== 4. Verify cache is purged ==== 
- 
- 4.1 check cache file -- gone 
-<​file>​ 
-   ​[test@test ~]$ ls -lrt */*/* 
- 
-   ​9/​c/​6:​ 
-   total 0 
-   ​[test@test ~]$  
-</​file>​ 
- 
- 4.2 request resource 3rd time from browser, *no* '​X-Litespeed-Cache:​ hit' response header received. 
-<​file>​ 
-   Date: Wed, 02 May 2012 23:42:18 GMT 
-   ​Content-Encoding:​ gzip 
-   ​Transfer-Encoding:​ Identity 
-   ​Connection:​ close 
-   ​Server:​ LiteSpeed 
-   Vary: Accept-Encoding 
-   ​Content-Type:​ text/html 
-</​file>​ 
  • Admin
  • Last modified: 2015/04/20 18:29
  • by Serge Espitia