• 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): 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?

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter n1fdadmin

    (@n1fdadmin)

    P.S. This code is only run by users with admin permissions.

    Plugin Contributor Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    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

    (@n1fdadmin)

    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)

    (@ipstenu)

    ?????? Advisor and Activist

    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 https://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.