Title: Help with purge from PHP
Last modified: September 7, 2017

---

# Help with purge from PHP

 *  [n1fdadmin](https://wordpress.org/support/users/n1fdadmin/)
 * (@n1fdadmin)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/help-with-purge-from-php/)
 * I wrote the following PHP script code to purge the entire varnish cache on our
   site:
 *     ```
       // Construct Varnish Cache purge URL
       $scheme = parse_url( $_SERVER[HTTP_REFERER], PHP_URL_SCHEME );
       $host = parse_url( $_SERVER[HTTP_REFERER], PHP_URL_HOST );
       $tmpURL = $scheme . "://" . $host . "/?vhp_flush_all=1" ;
       $purgeURL = wp_nonce_url( $tmpURL, 'vhp-flush-all') ;
   
       // Do the purge
       file_get_contents( $purgeURL );
       ```
   
 * This code was working fine but recently I am getting the following error when
   it executes –
    Warning: file_get_contents([https://www.n1fd.org/?vhp_flush_all=1&_wpnonce=a44652dfad](https://www.n1fd.org/?vhp_flush_all=1&_wpnonce=a44652dfad)):
   failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in …
 * If I execute the same URL from by browser, the purge works fine. I am obviously
   doing something wrong here – can you help me to understand how to correctly purge
   the varnish cache from PHP?
    -  This topic was modified 8 years, 8 months ago by [Ipstenu (Mika Epstein)](https://wordpress.org/support/users/ipstenu/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fhelp-with-purge-from-php%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [n1fdadmin](https://wordpress.org/support/users/n1fdadmin/)
 * (@n1fdadmin)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/help-with-purge-from-php/#post-9472848)
 * P.S. This code is only run by users with admin permissions.
 *  Plugin Contributor [Ipstenu (Mika Epstein)](https://wordpress.org/support/users/ipstenu/)
 * (@ipstenu)
 * 🏳️‍🌈 Advisor and Activist
 * [8 years, 8 months ago](https://wordpress.org/support/topic/help-with-purge-from-php/#post-9477773)
 * > I wrote the following PHP script code to purge the entire varnish cache on 
   > our site:
 * Why? If, as you say, it’s only run by admins, then they can just press the purge
   button in the toolbar, which does the same thing.
 *  Thread Starter [n1fdadmin](https://wordpress.org/support/users/n1fdadmin/)
 * (@n1fdadmin)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/help-with-purge-from-php/#post-9477811)
 * Thank you for getting back to me Mika. I have a script which handles several 
   levels of purging depending upon what I am doing. Steps include varnish purge,
   a css and java compression cache, and an external CDN. It’s useful for our admins
   to be able to just click a link based upon what they need and the php script 
   handles all of the steps in the correct order.
 *  Plugin Contributor [Ipstenu (Mika Epstein)](https://wordpress.org/support/users/ipstenu/)
 * (@ipstenu)
 * 🏳️‍🌈 Advisor and Activist
 * [8 years, 7 months ago](https://wordpress.org/support/topic/help-with-purge-from-php/#post-9553756)
 * I hate to phrase it this way, but you don’t NEED this plugin then 🙂
 * If you’re writing a script that does all that, just put the actual `curl -X PURGE
   http://yourdomain.com/.*` command right in the script? Wouldn’t that be faster?

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Help with purge from PHP’ is closed to new replies.

 * ![](https://ps.w.org/varnish-http-purge/assets/icon-256x256.png?rev=3027185)
 * [Proxy Cache Purge](https://wordpress.org/plugins/varnish-http-purge/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/varnish-http-purge/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/varnish-http-purge/)
 * [Active Topics](https://wordpress.org/support/plugin/varnish-http-purge/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/varnish-http-purge/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/varnish-http-purge/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Ipstenu (Mika Epstein)](https://wordpress.org/support/users/ipstenu/)
 * Last activity: [8 years, 7 months ago](https://wordpress.org/support/topic/help-with-purge-from-php/#post-9553756)
 * Status: not resolved