Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
litespeed_wiki:cache:no-plugin-setup-guidline [2018/08/07 19:26] Lisa Clarke [LiteSpeed Cache (LSCache) Introduction] Fixed formatting |
litespeed_wiki:cache:no-plugin-setup-guidline [2020/08/13 17:16] Jackson Zhang [How to purge cache by URL] |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== LiteSpeed Cache (LSCache) Introduction ====== | ====== LiteSpeed Cache (LSCache) Introduction ====== | ||
- | LiteSpeed has created a built-in cache functionality for it's Enterprise Edition web server. LSCache is included free in 2-CPU+ licenses and as an add-on for other licenses. (Available since version 4.0) | + | LiteSpeed has created a built-in cache functionality for it's Enterprise Edition web server. LSCache is included free in the Free Starter, Site Owner, and Web Host licenses, as well as the 8-CPU legacy licenses, and is available as an add-on for the other legacy licenses. (Available since version 4.0) |
LSCache's features are very similar to those in Apache mod_cache, but implemented in a more efficient way. LiteSpeed cache works like Varnish. It is an output cache for dynamic contents, so the usage is not limited to PHP pages. Unlike Varnish, LiteSpeed cache is built into LiteSpeed's web server, thus eliminating one layer of reverse proxy. This translates into higher efficieny for static contents. The uniqueness of LiteSpeed cache is that it uses rewrite rules (either in configuration files or .htaccess) to control its behavior for maximum flexibility. | LSCache's features are very similar to those in Apache mod_cache, but implemented in a more efficient way. LiteSpeed cache works like Varnish. It is an output cache for dynamic contents, so the usage is not limited to PHP pages. Unlike Varnish, LiteSpeed cache is built into LiteSpeed's web server, thus eliminating one layer of reverse proxy. This translates into higher efficieny for static contents. The uniqueness of LiteSpeed cache is that it uses rewrite rules (either in configuration files or .htaccess) to control its behavior for maximum flexibility. | ||
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 ====== | ||