gen:enable_varnish
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| gen:enable_varnish [2024/04/02 03:21] – created kirtisingh | gen:enable_varnish [2025/11/08 05:55] (current) – kirtisingh | ||
|---|---|---|---|
| Line 32: | Line 32: | ||
| Please put this IP w.r.t. any software/ | Please put this IP w.r.t. any software/ | ||
| - | With WordPress you can easily use Varnish and enable auto-purging of content (when it changes), by using the [[https:// | + | With WordPress you can easily use Varnish and enable auto-purging of content (when it changes), by using the [[https:// |
| + | |||
| + | **In some scenarios, Proxy Cache Purge plugin might not flush the cache or may not be of help**\\ | ||
| + | - If the page you changed/ | ||
| + | - If a plugin/ | ||
| + | |||
| + | For those cases we advise that you append the following block of code to the functions.php file of your WordPress theme . If the functions.php file does not exist, please create one. | ||
| + | |||
| + | **Important : Please check verify the functionality after implementing it. This code snippet is provieded only as a goodwill gesture** | ||
| + | |||
| + | <code php> | ||
| + | function custom2_varnish_flush_all($upgrader_object, | ||
| + | |||
| + | preg_match('# | ||
| + | |||
| + | $vhost_dir=$matches[1]; | ||
| + | |||
| + | $hosts=array(); | ||
| + | |||
| + | $hosts[]=preg_replace('# | ||
| + | $hosts[]=' | ||
| + | |||
| + | for($i=0; | ||
| + | |||
| + | $ch = curl_init(); | ||
| + | |||
| + | curl_setopt($ch, | ||
| + | |||
| + | curl_setopt($ch, | ||
| + | |||
| + | curl_setopt($ch, | ||
| + | 'Host: ' | ||
| + | ' | ||
| + | )); | ||
| + | |||
| + | curl_setopt($ch, | ||
| + | |||
| + | $response = curl_exec($ch); | ||
| + | |||
| + | if (curl_errno($ch)) { | ||
| + | file_put_contents($vhost_dir.'/ | ||
| + | } else { | ||
| + | file_put_contents($vhost_dir.'/ | ||
| + | } | ||
| + | |||
| + | curl_close($ch); | ||
| + | |||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | function custom2_save_post_action($post_id, | ||
| + | |||
| + | if ( ' | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | preg_match('# | ||
| + | |||
| + | $vhost_dir=$matches[1]; | ||
| + | |||
| + | $hosts=array(); | ||
| + | |||
| + | $hosts[]=preg_replace('# | ||
| + | $hosts[]=' | ||
| + | |||
| + | for($i=0; | ||
| + | |||
| + | $ch = curl_init(); | ||
| + | |||
| + | curl_setopt($ch, | ||
| + | |||
| + | curl_setopt($ch, | ||
| + | |||
| + | curl_setopt($ch, | ||
| + | 'Host: ' | ||
| + | )); | ||
| + | |||
| + | curl_setopt($ch, | ||
| + | |||
| + | $response = curl_exec($ch); | ||
| + | |||
| + | if (curl_errno($ch)) { | ||
| + | file_put_contents($vhost_dir.'/ | ||
| + | } else { | ||
| + | file_put_contents($vhost_dir.'/ | ||
| + | } | ||
| + | |||
| + | curl_close($ch); | ||
| + | |||
| + | } | ||
| + | |||
| + | |||
| + | } | ||
| + | |||
| + | add_action( ' | ||
| + | |||
| + | add_action( ' | ||
| + | </ | ||
| In some scenarios auto-purging of Varnish cache may not happen even after using the Proxy Cache Purge plugin. Then in that case Purge/ | In some scenarios auto-purging of Varnish cache may not happen even after using the Proxy Cache Purge plugin. Then in that case Purge/ | ||
gen/enable_varnish.1712028072.txt.gz · Last modified: 2024/04/02 03:21 by kirtisingh
