Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Last revision Both sides next revision | ||
litespeed_wiki:cache:no-plugin-setup-guidline [2019/05/17 18:32] Kacey Schroeder [LiteSpeed Cache (LSCache) Introduction] |
litespeed_wiki:cache:no-plugin-setup-guidline [2020/08/13 17:16] Jackson Zhang [How to purge cache by URL] |
||
---|---|---|---|
Line 270: | Line 270: | ||
===== How to purge cache by URL ===== | ===== How to purge cache by URL ===== | ||
- | There is a PHP script built into LSWS which will allow you to purge the cache by URL. It is located at ''/usr/local/lsws/admin/misc/purge_cache_byurl.php'' | + | There is a script built into LSWS which will allow you to purge the cache by URL. It is located at ''/usr/local/lsws/admin/misc/purge_cache_by_url'' |
<code> | <code> | ||
- | Usage: php $argv[0] -(r|p) domain url [server_ip] [port] | + | Usage: purge_cache_byurl -(r|p) [-ip <ip>] <URL> |
- | -r method option: Refresh cache (use stale cache while updating cache) | + | |
- | -p method option: Purge cache (delete cache entry) | + | Purge/Refresh cache for specific URL. |
- | domain: required parameter for domain name | + | |
- | url: required parameter for url | + | Required Arguments: |
- | server_ip: optional parameter, default is 127.0.0.1 | + | -r|-p, Refreshes/Purges the cache for specific page. |
- | server_port: optional parameter, default is 80 | + | *, Full URL of the specific page to refresh/purge. |
+ | |||
+ | Optional Arguments: | ||
+ | -ip, IP to resolve the hostname of the request to (Only | ||
+ | if it differs from what the DNS A record is set to.) | ||
+ | |||
+ | Notes: | ||
+ | If running on a server other than the one the site is located on, | ||
+ | make sure to add this machines IP to the trusted list inside of | ||
+ | LiteSpeed Web Server or else the Purge/Refresh requests will not | ||
+ | work. | ||
</code> | </code> | ||
**Example 1:** | **Example 1:** | ||
<code> | <code> | ||
- | /usr/local/lsws/admin/fcgi-bin/admin_php5 /usr/local/lsws/admin/misc/purge_cache_byurl.php -r mywebsite.com /index.php | + | /usr/local/lsws/admin/misc/purge_cache_by_url -r mywebsite.com |
</code> | </code> | ||
Line 290: | Line 300: | ||
<code> | <code> | ||
- | /usr/local/lsws/admin/misc>php purge_cache_byurl.php -p www.domain.com / | + | /usr/local/lsws/admin/misc>./purge_cache_by_url -p www.domain.com |
HTTP/1.0 200 Purged | HTTP/1.0 200 Purged | ||
Date: Wed, 03 Jun 2015 05:48:31 GMT | Date: Wed, 03 Jun 2015 05:48:31 GMT | ||
Line 301: | Line 311: | ||
**Note2:** Server_ip can not be omitted in some cases! | **Note2:** Server_ip can not be omitted in some cases! | ||
- | The script code: | ||
- | <code> | ||
- | <?php | ||
- | /**** | ||
- | * purge_cache_byurl | ||
- | * | ||
- | * Example: /usr/local/lsws/admin/fcgi-bin/admin_php5 /usr/local/lsws/admin/misc/purge_cache_byurl.php -r mywebsite.com /index.php | ||
- | */ | ||
- | |||
- | if ($argc < 4 || $argc > 6) { | ||
- | echo "Invalid arguments!\n"; | ||
- | echo "Usage: php $argv[0] -(r|p) domain url [server_ip] [port] | ||
- | -r method option: Refresh cache (use stale cache while updating cache) | ||
- | -p method option: Purge cache (delete cache entry) | ||
- | domain: required parameter for domain name | ||
- | url: required parameter for url | ||
- | server_ip: optional parameter, default is 127.0.0.1 | ||
- | server_port: optional parameter, default is 80 | ||
- | "; | ||
- | exit; | ||
- | } | ||
- | if ( $argv[1] == '-p' ) | ||
- | $method = "PURGE"; | ||
- | else if ($argv[1] == '-r' ) | ||
- | $method = "REFRESH"; | ||
- | else | ||
- | { | ||
- | echo "ERROR: unknown or missing method option"; | ||
- | exit; | ||
- | } | ||
- | $domain = $argv[2]; | ||
- | $url = $argv[3]; | ||
- | $server_ip = ($argc >= 5) ? $argv[4] : '127.0.0.1'; | ||
- | $port = ($argc == 6) ? $argv[5] : 80; | ||
- | |||
- | |||
- | $fp = fsockopen($server_ip, $port, $errno, $errstr, 2); | ||
- | if (!$fp) { | ||
- | echo "$errstr ($errno)\n"; | ||
- | } else { | ||
- | $out = "$method $url HTTP/1.0\r\n" | ||
- | . "Host: $domain\r\n" | ||
- | . "Connection: Close\r\n\r\n"; | ||
- | fwrite($fp, $out); | ||
- | while (!feof($fp)) { | ||
- | echo fgets($fp, 128); | ||
- | } | ||
- | fclose($fp); | ||
- | } | ||
- | |||
- | ?> | ||
- | |||
- | </code> | ||
====== Examples ====== | ====== Examples ====== | ||